/* ==========================================================
   工区结算系统 · 样式（自包含，无外部 CDN）
   ========================================================== */
:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --line: #e4e9f2;
  --line-strong: #d3dae6;
  --text: #1c2536;
  --muted: #6b7688;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eef3ff;
  --green: #0f9d58;
  --green-soft: #e9f7ef;
  --red: #d92d20;
  --red-soft: #fdf0ef;
  --amber: #b45309;
  --amber-soft: #fef6e7;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 6px 18px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

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

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

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: .2px; }

/* ---------- 布局 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 18px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #4f8bff);
  display: grid; place-items: center; color: #fff;
}
.brand-mark svg { width: 17px; height: 17px; }

.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--primary-soft); color: var(--primary-dark); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 6px; border: 1px solid var(--line);
  border-radius: 999px; background: #fbfcfe;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-dark);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
}
.user-chip .name { font-weight: 600; font-size: 13px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-tag {
  font-size: 11px; padding: 1px 6px; border-radius: 4px;
  background: var(--green-soft); color: var(--green); font-weight: 600;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 18px 48px;
}

.viewing-banner {
  background: var(--amber-soft);
  border: 1px solid #f3ddb1;
  color: var(--amber);
  padding: 9px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.card-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 650;
}
.card-title .ic { color: var(--primary); display: grid; place-items: center; }
.card-title .sub { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field-note { font-size: 12px; color: var(--muted); line-height: 1.35; }
.label-note { font-size: 11.5px; color: var(--muted); font-weight: 400; margin-left: 4px; }

.input, select.input, textarea.input {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 9px 11px; resize: vertical; }
.input:focus, select.input:focus, textarea.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.input:disabled, .input[readonly] { background: #f7f9fc; color: #475569; }
.input.err { border-color: var(--red); }

.form-grid { display: grid; grid-template-columns: 1.1fr 1.4fr .8fr .8fr .9fr auto; gap: 12px; align-items: end; }
.form-grid .actions { display: flex; flex-direction: row; gap: 8px; align-items: center; align-self: end; }
.form-grid .fw-half { grid-column: span 3; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 15px;
  border: 1px solid transparent; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, box-shadow .15s, transform .05s;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(37, 99, 235, .25); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover { background: #f7f9fc; }
.btn-soft { background: var(--primary-soft); color: var(--primary-dark); }
.btn-soft:hover { background: #e3ebff; }
.btn-danger { background: var(--red-soft); color: var(--red); border-color: #f6d5d2; }
.btn-danger:hover { background: #fbe4e2; }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #0c8549; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn-icon { width: 30px; height: 30px; padding: 0; border-radius: 7px; }
.btn-icon svg { width: 14px; height: 14px; }

/* ---------- 工具栏 ---------- */
.toolbar {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
}
.toolbar .field { min-width: 150px; }
.toolbar .spacer { flex: 1 1 auto; }
.toolbar .btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow-sm);
}
.stat .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: .3px; }
.stat .value small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.stat .value.money { color: var(--primary-dark); }
.stat .foot { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table.data { width: 100%; border-collapse: collapse; min-width: 820px; }
table.data th, table.data td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
table.data thead th {
  background: #f7f9fc;
  color: #475569;
  font-size: 12.5px;
  font-weight: 600;
  position: sticky; top: 0; z-index: 5;
  border-bottom: 1px solid var(--line-strong);
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.center, table.data th.center { text-align: center; }
table.data tbody tr:nth-child(even) { background: #fbfcfe; }
table.data tbody tr:hover { background: var(--primary-soft); }
table.data tbody tr.total-row { background: #f2f6ff; font-weight: 700; }
table.data tbody tr.total-row td { border-top: 2px solid #dbe6ff; border-bottom: none; }
table.data td .quiet { color: var(--muted); font-size: 12.5px; }

#recordTable { table-layout: fixed; }
#recordTable th:nth-child(1) { width: 56px; }
#recordTable th:nth-child(2) { width: 108px; }
#recordTable th:nth-child(3) { width: 130px; }
#recordTable th:nth-child(4) { width: auto; }
#recordTable th:nth-child(5) { width: 88px; }
#recordTable th:nth-child(6) { width: 96px; }
#recordTable th:nth-child(7) { width: 108px; }
#recordTable th:nth-child(8) { width: 160px; }
#recordTable th:nth-child(9) { width: 92px; }
.empty { padding: 46px 12px; text-align: center; color: var(--muted); }
.empty svg { width: 34px; height: 34px; opacity: .4; }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: #f1f5fb; color: #475569; font-size: 12px; font-weight: 600;
}

/* ---------- 汇总 ---------- */
#summaryCard .table-wrap { max-width: 900px; }
.scroll-hint { display: none; }

.summary-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 88px; gap: 10px; align-items: center; margin-bottom: 9px; }
.bar-row .name { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: #eef2f8; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #4f8bff, #2563eb); border-radius: 999px; }
.bar-row .val { text-align: right; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 下拉建议 ---------- */
.style-wrap { position: relative; }
.suggest {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 230px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: var(--shadow-md);
}
.suggest[hidden] { display: none; }
.suggest-item { padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.suggest-item:hover, .suggest-item.active { background: var(--primary-soft); }
.suggest-item .p { color: var(--primary-dark); font-weight: 600; }
.suggest-empty { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 18px; box-sizing: border-box;
  overflow-y: auto;
}
.modal-mask[hidden] { display: none !important; }
.modal {
  width: 100%; max-width: 520px; background: #fff; border-radius: 14px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
  max-height: 90vh; display: flex; flex-direction: column;
  margin: auto; position: relative;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: grid; gap: 12px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; }
.modal-close:hover { background: #f2f5fa; color: var(--text); }
.modal-close svg { width: 18px; height: 18px; display: block; }
body.modal-open { overflow: hidden; }

/* ---------- 提示条 ---------- */
.toast-wrap { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  min-width: 200px; max-width: 340px;
  padding: 10px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-md); color: #fff; background: #334155;
  animation: toast-in .18s ease-out;
}
.toast.success { background: #0f9d58; }
.toast.error { background: #d92d20; }
.toast.warning { background: #b45309; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 登录页 ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1000px 600px at 12% -10%, #e8efff 0%, transparent 60%),
  radial-gradient(900px 500px at 92% 108%, #e9f7ef 0%, transparent 55%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-md); padding: 32px 30px; }
.login-card .brand { justify-content: center; margin-bottom: 6px; font-size: 20px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card .field { margin-bottom: 14px; }
.login-card .input { height: 42px; }
.login-card .btn { width: 100%; height: 42px; margin-top: 6px; }
.login-error { background: var(--red-soft); color: var(--red); border: 1px solid #f6d5d2; padding: 9px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; }
.login-tip { margin-top: 16px; font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.7; }
.login-tip b { color: var(--text); }

/* ---------- 空数据 / footer ---------- */
.foot { max-width: 1280px; margin: 0 auto; padding: 8px 18px 32px; color: #94a3b8; font-size: 12.5px; text-align: center; }

/* ---------- 响应式 ---------- */
@media (max-width: 1024px) {
  .form-grid { grid-template-columns: 1fr 1fr 1fr; }
  .form-grid .actions { grid-column: 1 / -1; justify-content: flex-end; }
  .form-grid .fw-half { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .scroll-hint { display: block; font-size: 12px; color: var(--muted); text-align: right; margin: 6px 2px 0; }
  table.data { min-width: 700px; }
  .topbar-inner { height: auto; padding: 10px 14px; flex-wrap: wrap; gap: 10px; }
  .nav { margin-left: 0; width: 100%; }
  .nav a { padding: 6px 10px; font-size: 13px; }
  .page { padding: 14px 12px 36px; }
  .card { padding: 14px 14px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .fw-half { grid-column: 1 / -1; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 20px; }
  .toolbar .field { flex: 1 1 140px; min-width: 0; }
  .login-card { padding: 26px 20px; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- 打印 ---------- */
.print-only-title { display: none; }
.print-sign { display: none; }

@media print {
  .topbar, .nav, .toolbar, .btn, .viewing-banner, .no-print, .toast-wrap, .foot, .modal-mask { display: none !important; }
  body { background: #fff; }
  .page { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; margin: 0; }
  .print-head { display: block !important; margin-bottom: 10px; }
  .print-only-title { display: block; font-size: 12pt; margin: 18px 0 8px; }
  .print-sign { display: flex; justify-content: space-between; gap: 18px; margin-top: 26px; font-size: 10.5pt; color: #333; }
  #summaryCard .table-wrap { max-width: none; }
  table.data { min-width: 0; width: 100%; font-size: 10.5pt; table-layout: fixed; }
  table.data th, table.data td { border: 1px solid #999; white-space: nowrap; padding: 5px 6px; overflow: hidden; }
  #recordTable th:nth-child(1) { width: 6%; }
  #recordTable th:nth-child(2) { width: 13%; }
  #recordTable th:nth-child(3) { width: 16%; }
  #recordTable th:nth-child(4) { width: 18%; }
  #recordTable th:nth-child(5) { width: 9%; }
  #recordTable th:nth-child(6) { width: 9%; }
  #recordTable th:nth-child(7) { width: 12%; }
  #recordTable th:nth-child(8) { width: 17%; }
  #summaryCard table.data th:nth-child(1) { width: 30%; }
  #summaryCard table.data th:nth-child(2) { width: 16%; }
  #summaryCard table.data th:nth-child(3) { width: 18%; }
  #summaryCard table.data th:nth-child(4) { width: 18%; }
  #summaryCard table.data th:nth-child(5) { width: 18%; }
  table.data thead th { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.data tbody tr:nth-child(even) { background: #fff !important; }
  .table-wrap { border: 0; overflow: visible; }
  .summary-grid { display: block; }
  .summary-grid > div + div { margin-top: 14px; page-break-inside: avoid; }
  .bar-row { grid-template-columns: 90px 1fr 80px; }
  @page { size: A4; margin: 14mm 12mm; }
}
.print-head { display: none; }
.print-head h1 { font-size: 16pt; text-align: center; margin-bottom: 6px; }
.print-head p { text-align: center; color: #555; font-size: 10pt; margin: 0 0 10px; }
