:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f1f3f6; --border: #e1e5eb;
  --text: #1c2330; --text-2: #4a5566; --muted: #6b7686;
  --accent: #2458d6; --accent-soft: #e8eefc;
  --ok: #12805c; --ok-soft: #e3f4ec; --warn: #9a6200; --warn-soft: #fcf1dc;
  --bad: #c0362c; --bad-soft: #fbe6e4; --info-soft: #eef1f5;
  --radius: 10px; --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 1px 3px rgba(20, 30, 50, .04);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
          "Noto Sans CJK SC", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c; --surface: #181e27; --surface-2: #1f2631; --border: #2b3441;
    --text: #e6ebf2; --text-2: #b8c2d0; --muted: #8b97a8;
    --accent: #7ea2ff; --accent-soft: #1d2b4d;
    --ok: #4cc79a; --ok-soft: #13342a; --warn: #e6b04f; --warn-soft: #3a2d12;
    --bad: #f07a70; --bad-soft: #3f1b19; --info-soft: #232b37;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.65 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85em; }
[hidden] { display: none !important; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; white-space: nowrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs a { padding: 16px 12px 14px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.count { display: inline-block; margin-left: 6px; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad); color: #fff; font-size: .75rem; line-height: 20px; text-align: center; }
.topbar-side { display: flex; align-items: center; gap: 12px; }

.page { max-width: 1120px; margin: 0 auto; padding: 24px 16px 48px; }
.footer { max-width: 1120px; margin: 0 auto; padding: 0 16px 32px; }
.notice { max-width: 1120px; margin: 12px auto 0; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }

/* Layout */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.grid > .card + .card { margin-top: 0; }
.card-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-title h3 { margin: 0; }

/* Status banner */
.banner { border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; border: 1px solid var(--border); }
.banner h2 { margin-bottom: 4px; }
.banner.ok { background: var(--ok-soft); border-color: transparent; }
.banner.warn { background: var(--warn-soft); border-color: transparent; }
.banner.bad { background: var(--bad-soft); border-color: transparent; }
.banner.info { background: var(--info-soft); border-color: transparent; }
.banner ul { margin: 8px 0 0; padding-left: 20px; }

/* Stats */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat-note { color: var(--muted); font-size: .8rem; }
.stat-value.sm { font-size: 1.05rem; }
.mt { margin-top: 24px; }
.funnel { display: flex; gap: 8px; flex-wrap: wrap; align-items: stretch; }
.funnel .step { flex: 1 1 120px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.funnel .arrow { align-self: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* Key/value */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 8px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Forms */
label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: .92rem; }
input[type=text], input[type=password], input[type=search], textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; }
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 6px 0; font-size: .9rem; }
.btn { font: inherit; font-size: .92rem; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-ok { border-color: var(--ok); color: var(--ok); } .btn-bad { border-color: var(--bad); color: var(--bad); }
.btn-warn { border-color: var(--warn); color: var(--warn); }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 10px; font-size: .85rem; }
.btn-block { width: 100%; margin-top: 8px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 180px; }

/* Reader */
.reader { max-width: 820px; }
.reader-meta { color: var(--muted); font-size: .85rem; margin-bottom: 16px; word-break: break-all; }
.md { font-size: 1rem; line-height: 1.8; overflow-wrap: anywhere; }
.md h1 { font-size: 1.45rem; margin-top: 1.2em; } .md h2 { font-size: 1.2rem; margin-top: 1.4em; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 1.05rem; margin-top: 1.2em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 .8em; }
.md li { margin: .2em 0; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--surface-2); padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 .8em; padding: 6px 14px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; }
.md table { margin: .6em 0 1em; display: block; overflow-x: auto; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }

.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-plain li:last-child { border-bottom: none; }
details summary { cursor: pointer; color: var(--accent); margin: 6px 0; }
.reply { margin-top: 8px; padding: 10px 12px; background: var(--ok-soft); border-radius: 8px; }
.pending { margin-top: 8px; padding: 10px 12px; background: var(--warn-soft); border-radius: 8px; }

/* Chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--border); } .chart .label { fill: var(--muted); font-size: 11px; }
.chart .line-total { stroke: var(--accent); fill: none; stroke-width: 2; }
.chart .line-cash { stroke: var(--ok); fill: none; stroke-width: 2; stroke-dasharray: 5 4; }
.legend { display: flex; gap: 18px; font-size: .85rem; color: var(--text-2); margin-top: 8px; }
.legend .swatch { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-right: 6px; background: var(--accent); }
.legend .swatch.cash { background: var(--ok); }

/* Login */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }

@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar-inner { gap: 8px; }
  .tabs { order: 3; width: 100%; flex-basis: 100%; }
  .tabs a { padding: 10px 10px 8px; }
  .page { padding-top: 16px; }
  .card { padding: 14px 14px; }
  .kv { grid-template-columns: 1fr; gap: 0; } .kv dd { margin-bottom: 6px; }
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 10px 12px; } .stat-value { font-size: 1.2rem; }
  .stack thead { display: none; }
  .stack tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .stack tr:last-child { border-bottom: none; }
  .stack td { border: none; padding: 0; }
  .stack td.summary { flex-basis: 100%; color: var(--text-2); }
  .funnel .arrow { display: none; } .funnel .step { flex-basis: calc(50% - 4px); }
}
