:root {
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --border: #e2e0db;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --negative: #d03b3b;
  --good: #0ca30c;
  --warning: #b07800;
  --font: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface); color: var(--text-primary); font: 14px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); padding: 1px 4px; border-radius: 3px; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--border);
          background: #fff; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text-primary); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { padding: 4px 10px; border-radius: 6px; color: var(--text-secondary); }
.topbar nav a.on { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
.logout button { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 24px 0 8px; }
.muted { color: var(--text-muted); }
.note { color: var(--text-secondary); font-size: 13px; margin: 4px 0 8px; }

.flash { padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; background: var(--surface-2); }
.flash.error { background: #fbeaea; color: var(--negative); }
.flash.ok { background: #e8f6e8; color: #136b13; }
.err { color: var(--negative); }

.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: end; padding: 10px 12px; background: #fff;
           border: 1px solid var(--border); border-radius: 8px; margin-bottom: 16px; }
.filters fieldset { border: 0; padding: 0; margin: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.filters legend, .filters label { font-size: 12px; color: var(--text-secondary); }
.filters select, .filters input[type=text] { font: inherit; padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px; }
.filters .disabled { opacity: .45; }
.pagebar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.version { font-size: 12px; color: var(--text-muted); }

button.primary, a.button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 14px;
                           cursor: pointer; font: inherit; display: inline-block; }
button.secondary { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 6px 14px; cursor: pointer; font: inherit; }
button[disabled] { opacity: .4; cursor: not-allowed; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.kpi .label { font-size: 12px; color: var(--text-secondary); }
.kpi .value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .value.neg { color: var(--negative); }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; margin-bottom: 8px; }
.chart { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.chart .canvas { height: 300px; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { background: var(--surface-2); text-align: left; position: sticky; top: 0; cursor: pointer; user-select: none; }
table.data th[data-dir=asc]::after { content: " ▲"; font-size: 10px; }
table.data th[data-dir=desc]::after { content: " ▼"; font-size: 10px; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.neg { color: var(--negative); }
table.data tr.total td { font-weight: 700; background: var(--surface-2); }
table.data tr:hover td { background: #f7f6f3; }

.upload-box { background: #fff; border: 2px dashed var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.status-ok { color: var(--good); }
.status-bad { color: var(--negative); }
.status-warn { color: var(--warning); }
.login-box { max-width: 360px; margin: 12vh auto; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 24px; }
.login-box label { display: block; margin-bottom: 12px; color: var(--text-secondary); }
.login-box input { display: block; width: 100%; margin-top: 4px; padding: 8px; font: inherit; border: 1px solid var(--border); border-radius: 6px; }

@media (max-width: 720px) {
  /* 手机：导航单独一行、横向滑动，不再折成好几行把内容挤到下面 */
  .topbar { gap: 8px 16px; }
  .topbar nav { order: 3; flex-basis: 100%; min-width: 0; flex-wrap: nowrap; overflow-x: auto;
                -webkit-overflow-scrolling: touch; }
  .topbar nav a { white-space: nowrap; flex: none; }
  .logout { margin-left: auto; }
}

@media (max-width: 640px) {
  .charts { grid-template-columns: 1fr; }
  .kpi .value { font-size: 18px; }
}
