:root {
  --green: #00693e;
  --green-soft: #e6f2ec;
  --ink: #1b1f1d;
  --muted: #6b7370;
  --line: #dfe4e1;
  --bg: #f4f6f5;
  --card: #ffffff;
  --error: #b3261e;
  --tabbar: 58px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 8px);
  -webkit-text-size-adjust: 100%;
}

main { max-width: 820px; margin: 0 auto; padding: 12px 12px 24px; }

.skip {
  position: absolute; left: -999px; top: 0; background: #fff; color: var(--green);
  padding: 8px 12px; z-index: 20;
}
.skip:focus { left: 8px; top: 8px; }

a { color: var(--green); }

:focus-visible { outline: 3px solid #0a7f52; outline-offset: 2px; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: var(--green); color: #fff;
}
.topbar .brand { font-weight: 600; font-size: 17px; margin-right: auto; }
.topbar .today { font-size: 12px; opacity: .8; font-variant-numeric: tabular-nums; }
.topbar .logout { margin: 0; }
.linkbtn {
  background: none; border: 0; color: #fff; font-size: 14px; min-height: 44px; padding: 6px 4px;
  text-decoration: underline; text-underline-offset: 3px;
}

/* ---------- 底栏 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; align-items: center; justify-content: center;
  min-height: var(--tabbar); color: var(--muted); text-decoration: none; font-size: 15px;
}
.tabbar a.active { color: var(--green); font-weight: 600; box-shadow: inset 0 2px 0 var(--green); }

/* ---------- 通用块 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin: 0 0 12px;
}
.card-title { margin: 0 0 10px; font-size: 16px; color: var(--green); }
.subhead { margin: 14px 0 6px; font-size: 14px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 12px; }
.summary { color: var(--muted); font-size: 13px; margin: 8px 0; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; margin: 0; }

.alert {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 14px;
}
.alert.error { background: #fdeceb; color: var(--error); border: 1px solid #f6c9c5; }
.alert.ok { background: #e7f4ec; color: #0d5a34; border: 1px solid #bfe3cf; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
input, textarea, select {
  min-width: 0; max-width: 100%;
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #c9d1cd; border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 120px; }
.toolbar { display: flex; gap: 10px; margin: 0 0 10px; }
.toolbar .field { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.btn {
  font: inherit; border: 1px solid #c9d1cd; background: #fff; color: var(--ink);
  border-radius: 10px; padding: 0 14px; min-height: 44px; cursor: pointer;
}
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn.small { min-height: 44px; padding: 0 10px; font-size: 14px; }
.btn.busy { opacity: .6; }

/* ---------- 录入 ---------- */
.tabs {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; display: inline-flex; align-items: center; min-height: 44px;
  padding: 0 14px; border-radius: 999px; border: 1px solid #c9d1cd;
  background: #fff; color: var(--ink); text-decoration: none; font-size: 14px;
}
.tab.active { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }

.report-out { width: 100%; font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; min-height: 320px; white-space: pre-wrap; }
.person-card .card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.person-card .card-title { margin: 0; }
.person-body .subhead { margin: 10px 0 4px; }
.metric-line { display: flex; align-items: baseline; gap: 6px; margin: 3px 0; font-size: 15px; }
.metric-line b { font-variant-numeric: tabular-nums; margin-left: auto; }
.metric-line em { font-style: normal; font-size: 12px; color: var(--muted); min-width: 2.5em; }
.tag { font-size: 11px; color: #8a5a00; background: #fff4e0; border-radius: 4px; padding: 0 4px; }
.copy-src { display: none; }
.copybar { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; align-items: center; }
.copybar a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.fillform .grid { margin-bottom: 8px; }

.recorded { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 14px; }
.recorded li { display: flex; align-items: baseline; gap: 4px; }
.recorded b { font-variant-numeric: tabular-nums; }
.recorded em { font-style: normal; font-size: 11px; color: var(--muted); }
.recorded .muted { color: var(--muted); }
.preview td { text-align: right; }
.preview td input { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
.preview .newrow td.stick em { color: #a15c00; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cell { display: flex; flex-direction: column; gap: 4px; }
.cell-name { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: baseline; }
.cell-name em { font-style: normal; font-size: 11px; color: #8b938f; }
.cell input { font-variant-numeric: tabular-nums; }

.savebar {
  position: sticky; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding: 10px 0; background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex;
}
.savebar .btn { flex: 1; }

/* ---------- 表格 ---------- */
.tablewrap {
  overflow-x: auto; overflow-y: clip; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}
.matrix { border-collapse: collapse; width: 100%; font-size: 14px; }
.matrix th, .matrix td {
  padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.matrix thead th {
  position: sticky; top: 0; z-index: 3;
  background: #f7f9f8; color: var(--muted); font-weight: 600; font-size: 13px;
}
.matrix td.stick { position: sticky; left: 0; z-index: 2; background: #fff; text-align: left; }
.matrix th.stick {
  position: sticky; left: 0; z-index: 2; background: #fff; text-align: left;
  font-weight: 500; min-width: 96px;
}
.matrix thead th.stick { background: #f7f9f8; }
.matrix td { text-align: right; font-variant-numeric: tabular-nums; }
.matrix td.total { font-weight: 600; background: #fbfdfc; }
.matrix .grouprow th {
  background: var(--green-soft); color: var(--green); text-align: left; font-size: 13px;
  padding: 6px 10px;
}
.matrix em { font-style: normal; font-size: 11px; color: #8b938f; margin-left: 4px; }
.matrix .sumrow th, .matrix .sumrow td { background: #f7f9f8; font-weight: 600; }
.num { display: block; }
.bar { display: block; height: 4px; margin-top: 4px; background: #e8ece9; border-radius: 2px; }
.bar i { display: block; height: 4px; background: var(--green); border-radius: 2px; }

/* ---------- 设置 ---------- */
.rowform {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 0; border-bottom: 1px dashed var(--line);
}
.rowform:last-child { border-bottom: 0; }
.rowform .grow { flex: 1 1 140px; min-width: 120px; }
.rowform .unit { width: 72px; }
.state { font-size: 12px; color: var(--muted); }

/* ---------- 登录 / 初始化 ---------- */
.plain { padding-bottom: 0; }
.plain-main { max-width: 480px; margin: 0 auto; padding: 24px 16px 40px; }
.auth-card {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 20px; margin-top: 8vh;
}
.auth-card h1 { font-size: 22px; margin: 0 0 4px; color: var(--green); }

@media (min-width: 640px) {
  main { padding: 16px 20px 32px; }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
