:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #7b8794;
  --line: #e4e7eb;
  --accent: #2f6f9f;
  --accent-ink: #ffffff;
  --head: #eef2f6;
  --hover: #f0f6fb;
  --miss: #fdeaea;
  --error: #c0392b;
  --nest: #fafbfc;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}
button, input, select { font: inherit; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 600; color: var(--text); text-decoration: none; }
.who { display: flex; gap: 12px; align-items: center; color: var(--muted); }
main { max-width: 1400px; margin: 0 auto; padding: 20px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 20px; }
.login { max-width: 360px; margin: 80px auto; }
.login h1 { font-size: 20px; margin: 0 0 16px; }
.login label { display: block; margin-bottom: 14px; color: var(--muted); }
.login input { display: block; width: 100%; margin-top: 4px; }
input, select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { cursor: pointer; border-radius: 6px; border: 1px solid var(--line); background: #fff; padding: 7px 14px; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: .6; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
.login button.primary { width: 100%; padding: 9px; }
.error { color: var(--error); margin: 0 0 12px; }

h2 { font-size: 18px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.reports { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.report-tile { display: block; text-align: left; padding: 18px; height: 100%; }
.report-tile strong { display: block; font-size: 16px; margin-bottom: 6px; color: var(--text); }
.report-tile span { color: var(--muted); }
.back { margin-bottom: 12px; display: inline-block; }

.criteria { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin: 16px 0; }
.criteria label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.criteria select { min-width: 320px; max-width: 100%; }
.criteria small { color: var(--muted); font-size: 12px; }
.note { color: var(--muted); margin: 0 0 10px; }

/* ── grid ─────────────────────────────────────────────────────────── */
.grid-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.grid-toolbar .count { color: var(--muted); margin-left: auto; }
.grid-toolbar input { min-width: 200px; }
.grid-wrap { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
table.tg { border-collapse: separate; border-spacing: 0; width: 100%; }
.tg th, .tg td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tg th {
  background: var(--head); font-weight: 600; font-size: 13px; cursor: pointer; user-select: none;
}
.grid-wrap > table.tg > thead th { position: sticky; top: 0; z-index: 2; }
.tg th .arrow { color: var(--muted); font-size: 11px; margin-left: 3px; }
.tg td.num, .tg th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tg td.wrap { white-space: normal; min-width: 180px; max-width: 420px; }
.tg tbody tr.row:hover > td { background: var(--hover); }
.tg tr.has-kids { cursor: pointer; }
.tg tr.miss > td { background: var(--miss); }
.tg tr.muted > td { color: var(--muted); }
.tg td.tog { width: 28px; padding-right: 0; color: var(--muted); text-align: center; }
.tg tr.open > td.tog { color: var(--accent); }
.tg tr.nest > td { padding: 0 0 10px 28px; background: var(--nest); }
.tg tr.nest table.tg { border-left: 3px solid var(--accent); background: var(--card); }
.tg tr.nest table.tg th { background: #f3f5f8; font-size: 12px; position: static; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.loading { color: var(--muted); padding: 20px 0; }

@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .criteria select { min-width: 0; width: 100%; }
  .criteria label { width: 100%; }
}
