:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --line: #e4e8ee;
  --line-soft: #eef1f5;
  --text: #161a21;
  --text-2: #4c5563;
  --muted: #6b7482;
  --muted-2: #939ba7;

  --brand: #1c3a5e;
  --brand-dark: #142b46;
  --brand-2: #2a5f96;
  --brand-soft: #eaf1f8;

  --ok: #16785c;
  --ok-soft: #e6f4ee;
  --warn: #96620f;
  --warn-soft: #fbf2e2;
  --danger: #a8322c;
  --danger-soft: #fbeae8;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .03);
  --shadow-lg: 0 16px 36px rgba(16, 24, 40, .14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-2); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }

button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 16px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  transition: background .16s, border-color .16s, color .16s;
}
button:hover { background: var(--brand-dark); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: #fff; color: var(--text-2); border-color: var(--line); }
button.ghost:hover { background: #f7f9fb; border-color: #d3d9e2; color: var(--text); }
button.danger { background: var(--danger); }
button.danger:hover { background: #8d2823; }
button.sm { font-size: 12.5px; padding: 5px 11px; border-radius: 7px; }
button.link { background: none; border: none; color: var(--brand-2); padding: 0; font-size: 13px; }
button.link:hover { background: none; text-decoration: underline; }

input, select, textarea {
  font-family: inherit;
  font-size: 14.5px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
input::placeholder { color: var(--muted-2); }
input:focus, select:focus, textarea:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(42, 95, 150, .12);
}
input:disabled { background: #f6f8fa; color: var(--muted); }
label { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 5px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.hide { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 460px at 50% -10%, #e8eef6 0%, rgba(243, 245, 247, 0) 70%),
    var(--bg);
}
.login-box { width: 100%; max-width: 372px; }
.login-box .brand { text-align: center; margin-bottom: 22px; }
.login-box .brand .logo {
  width: 46px; height: 46px; border-radius: 13px; margin: 0 auto 14px;
  background: var(--brand); color: #fff; font-size: 20px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(28, 58, 94, .22);
}
.login-box h1 { font-size: 18px; margin-bottom: 6px; letter-spacing: 0; }
.login-box .form-card { padding: 24px 22px 20px; }
.field { margin-bottom: 15px; }
.err {
  background: var(--danger-soft); color: var(--danger); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; margin-bottom: 14px; display: none;
}
.err.show { display: block; }

/* ---------- 手机端 ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: #fff;
  padding: 13px 16px;
  display: flex; align-items: center; justify-content: space-between;
  padding-top: calc(13px + env(safe-area-inset-top));
}
.appbar .t { font-size: 15.5px; font-weight: 500; letter-spacing: .01em; }
.appbar .who { font-size: 12px; color: rgba(255, 255, 255, .7); margin-top: 1px; }
.appbar button {
  background: rgba(255, 255, 255, .1); color: #fff; font-size: 12.5px;
  padding: 5px 11px; border-radius: 7px; border: 1px solid rgba(255, 255, 255, .22);
}
.appbar button:hover { background: rgba(255, 255, 255, .2); }

.tabs {
  display: flex; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 15;
}
.tabs div {
  flex: 1; text-align: center; padding: 13px 0; font-size: 14.5px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
  transition: color .16s, border-color .16s;
}
.tabs div.on { color: var(--brand); font-weight: 600; border-bottom-color: var(--brand); }

.page { padding: 14px 14px 130px; max-width: 640px; margin: 0 auto; }

.period-bar {
  background: var(--brand-soft); border-radius: var(--radius);
  padding: 11px 14px; margin-bottom: 12px; font-size: 12.5px; color: var(--brand);
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center;
}
.period-bar b { font-weight: 600; }
.period-bar .tag {
  background: #fff; border: 1px solid #d5e2f0; border-radius: 20px;
  padding: 2px 10px; font-size: 11.5px; color: var(--brand-2);
}

.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-row input {
  font-size: 17px; letter-spacing: 1.5px; font-weight: 500;
  padding: 10px 13px;
}
.search-row button { white-space: nowrap; padding: 0 18px; }

.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.info-item {
  background: #f7f9fb; border: 1px solid var(--line-soft); border-radius: 9px;
  padding: 9px 12px;
}
.info-item .k { font-size: 11.5px; color: var(--muted-2); }
.info-item .v { font-size: 15.5px; font-weight: 500; margin-top: 1px; }

.field-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line-soft);
}
.field-row:last-child { border-bottom: none; }
.field-row .lb { flex: 1; font-size: 14.5px; color: var(--text-2); }
.field-row .lb .req { color: var(--danger); margin-left: 3px; }
.field-row .ipt { width: 106px; }
.field-row .ipt input {
  text-align: right; font-size: 16px; padding: 7px 10px; font-weight: 500;
  border-color: transparent; background: #f7f9fb;
}
.field-row .ipt input:focus { background: #fff; border-color: var(--brand-2); }
.field-row .unit { width: 28px; font-size: 12.5px; color: var(--muted-2); }

.total-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line);
  font-size: 14px; color: var(--text-2);
}
.total-row .tl { flex: 1; }
.total-row b { font-size: 20px; color: var(--brand); font-weight: 600; }
.total-row input {
  width: 122px; text-align: right; font-size: 18px; font-weight: 600;
  color: var(--brand); padding: 7px 10px; background: #f7f9fb;
  border-color: transparent;
}
.total-row input:focus { background: #fff; border-color: var(--brand-2); }

.section-title {
  font-size: 13px; font-weight: 600; margin: 0 0 6px;
  display: flex; justify-content: space-between; align-items: center;
  color: var(--text);
}

#editHint {
  font-size: 12px; line-height: 1.5; color: var(--muted-2);
  margin: -2px 0 10px; padding-left: 8px; border-left: 2px solid var(--line);
}
#editHint:empty { display: none; }

.submit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 11px 14px calc(11px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.submit-bar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.submit-bar button { flex: 1; padding: 13px; font-size: 15.5px; font-weight: 600; border-radius: 10px; }

.rec-item {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.rec-item .top { display: flex; justify-content: space-between; align-items: center; }
.rec-item .code { font-size: 16.5px; font-weight: 600; letter-spacing: 1px; }
.rec-item .meta { font-size: 12px; color: var(--muted-2); margin-top: 4px; }
.rec-item .act { margin-top: 11px; display: flex; gap: 8px; }

.notice {
  border-radius: var(--radius); padding: 10px 14px; font-size: 12.5px; margin-bottom: 12px;
  background: var(--warn-soft); color: var(--warn); border: 1px solid #f0e0c4;
}
.notice.info { background: var(--brand-soft); color: var(--brand); border-color: #d7e4f1; }
.notice.ok { background: var(--ok-soft); color: var(--ok); border-color: #c3e3d6; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(16px);
  background: rgba(22, 26, 33, .94); color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .22s; z-index: 100;
  max-width: 86%; text-align: center; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: rgba(22, 120, 92, .96); }
.toast.err { background: rgba(168, 50, 44, .96); }

/* ---------- 管理端 ---------- */
.admin-shell { display: flex; min-height: 100vh; }

.side {
  width: 196px; background: #fff; border-right: 1px solid var(--line);
  padding: 18px 0; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.side .brand {
  padding: 0 20px 20px; font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.side .brand::before {
  content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--brand);
  flex-shrink: 0;
}
.side nav a {
  display: block; padding: 9px 20px; color: var(--text-2); font-size: 13.5px;
  border-left: 2px solid transparent; transition: background .14s, color .14s;
}
.side nav a:hover { background: #f7f9fb; color: var(--text); }
.side nav a.on {
  background: var(--brand-soft); color: var(--brand);
  border-left-color: var(--brand); font-weight: 600;
}
.side .foot {
  position: absolute; bottom: 18px; left: 0; right: 0; padding: 0 20px;
  font-size: 12px; color: var(--muted-2);
}
.side .foot a { color: var(--muted); }
.side .foot a:hover { color: var(--brand-2); }

.main { flex: 1; padding: 22px 26px 60px; min-width: 0; }
.main h2 { font-size: 17px; margin-bottom: 3px; }
.main .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 25px; font-weight: 600; margin-top: 3px; letter-spacing: -.02em; }
.stat .v small { font-size: 12.5px; color: var(--muted-2); font-weight: 400; margin-left: 1px; }

table.tb {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow);
}
table.tb th, table.tb td {
  padding: 11px 14px; text-align: left; font-size: 13px;
  border-bottom: 1px solid var(--line-soft);
}
table.tb th {
  background: #fafbfc; font-weight: 500; color: var(--muted);
  font-size: 12px; letter-spacing: .02em; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
table.tb tbody tr:last-child td { border-bottom: none; }
table.tb tbody tr:hover td { background: #fafbfc; }
table.tb td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tb .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .5px; color: var(--text);
}

.bar { height: 5px; background: #eef1f5; border-radius: 3px; overflow: hidden; min-width: 70px; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.toolbar .f { min-width: 128px; }
.toolbar .f label { margin-bottom: 4px; }

.seg {
  display: inline-flex; border: 1px solid var(--line); border-radius: 9px;
  overflow: hidden; background: #fff;
}
.seg button {
  border: none; border-radius: 0; background: #fff; color: var(--muted);
  font-size: 12.5px; padding: 8px 13px;
}
.seg button:hover { background: #f7f9fb; color: var(--text); }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.pager {
  display: flex; gap: 10px; align-items: center; justify-content: flex-end;
  margin-top: 14px; font-size: 12.5px; color: var(--muted);
}

.badge {
  display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 6px;
  background: #f1f3f6; color: var(--muted); border: 1px solid transparent;
}
.badge.on { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 26, 34, .38); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  background: #fff; border-radius: var(--radius-lg); width: 100%; max-width: 460px;
  padding: 22px; max-height: 86vh; overflow: auto; box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 15.5px; margin-bottom: 14px; }
.modal .acts { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

@media (max-width: 820px) {
  .admin-shell { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; padding: 8px 0; border-right: none; border-bottom: 1px solid var(--line); }
  .side nav { display: flex; overflow-x: auto; }
  .side nav a { white-space: nowrap; border-left: none; border-bottom: 2px solid transparent; padding: 8px 14px; }
  .side nav a.on { border-left: none; border-bottom-color: var(--brand); }
  .side .foot, .side .brand { display: none; }
  .main { padding: 14px; }
}
