:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efeb;
  --line: #e3e1db;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8882;
  --series-1: #2a78d6;
  --series-1-soft: #2a78d61f;
  --accent: #2a78d6;
  --good: #0a7d3c;
  --warn: #9a6400;
  --bad: #c43535;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8d8c85;
    --series-1: #3987e5;
    --series-1-soft: #3987e526;
    --accent: #5a9cf0;
    --good: #4cc27c;
    --warn: #e0a53a;
    --bad: #ef7070;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c85;
  --series-1: #3987e5; --series-1-soft: #3987e526; --accent: #5a9cf0;
  --good: #4cc27c; --warn: #e0a53a; --bad: #ef7070;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* 顶栏 */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: .5px; }
.brand span { color: var(--muted); font-weight: 500; }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav a { color: var(--text-2); padding: 6px 12px; border-radius: 8px; white-space: nowrap; }
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.on { color: var(--text); background: var(--surface); box-shadow: 0 0 0 1px var(--line); font-weight: 600; }
.badge[hidden] { display: none; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; }

/* 筛选 */
.filters { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; padding: 16px 24px 0; max-width: 1240px; margin: 0 auto; }
.filters label { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
select, input[type="search"], input[type="text"] {
  height: 32px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.seg button { white-space: nowrap; border: 0; background: none; padding: 4px 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
button.ghost, button.btn { height: 32px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; }
button.ghost:hover, button.btn:hover { background: var(--surface-2); }
button.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
button.primary:hover { background: var(--text-2); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }

main { max-width: 1240px; margin: 0 auto; padding: 16px 24px 64px; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h2 small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* 数字卡 */
.stat .label { color: var(--text-2); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 650; letter-spacing: -.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
a.stat { color: inherit; display: block; }
a.stat:hover { text-decoration: none; border-color: var(--accent); }

/* 柱状图 */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { fill: color-mix(in srgb, var(--series-1) 80%, var(--text)); }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

/* 横向条形列表（同时就是表格） */
.hbars { display: grid; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .name small { color: var(--muted); margin-left: 4px; }
.hbar .track { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { font-variant-numeric: tabular-nums; text-align: right; min-width: 64px; }
.hbar .val small { color: var(--muted); margin-left: 4px; }
.hbar.clickable { cursor: pointer; }
.hbar.clickable:hover .name { color: var(--accent); }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
td.nowrap { white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }

/* 来信 */
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.toolbar input[type="search"] { flex: 1; min-width: 200px; }
.letter { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.letter + .letter { margin-top: 12px; }
.letter.new { border-left: 3px solid var(--accent); }
.letter-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--text-2); font-size: 13px; }
.letter-head .who { color: var(--text); font-weight: 600; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); }
.tag.bug { color: var(--bad); }
.tag.suggestion { color: var(--accent); }
.tag.premium { color: var(--warn); }
.letter-body { white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.7; margin: 10px 0 12px; }
.letter-contact { font-size: 13px; color: var(--text-2); margin: -4px 0 12px; }
.letter-photos { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.letter-photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; background: var(--line); }
.letter-photos a:hover img { border-color: var(--accent); }
.letter-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--muted); font-size: 12px; }
.letter-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.letter-actions button { height: 28px; padding: 0 10px; font-size: 12px; }

/* SQL */
textarea { width: 100%; min-height: 140px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); resize: vertical; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.presets button { height: 26px; padding: 0 10px; font-size: 12px; border-radius: 13px; }
.error { color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; padding: 8px 10px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: 0 6px 20px rgb(0 0 0 / .12); font-size: 12px;
}
.tooltip strong { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.tooltip span { color: var(--muted); }
.tooltip.wide { max-width: 340px; white-space: pre-line; line-height: 1.6; }
.tooltip.wide strong { font-size: 13px; margin-bottom: 4px; }
.tooltip.wide span { color: var(--text-2); }

/* 口径「?」 */
.q {
  display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; margin-left: 5px;
  border-radius: 50%; border: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 600;
  cursor: help; vertical-align: 1px; user-select: none;
}
.q:hover, .q:focus-visible { color: var(--text); border-color: var(--muted); outline: none; }
.subhead { color: var(--text-2); font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.section-head { margin: 24px 0 -4px; }

.loading { color: var(--muted); padding: 40px 0; text-align: center; }

@media (max-width: 640px) {
  .top { padding: 0 16px; gap: 12px; }
  .filters, main { padding-left: 16px; padding-right: 16px; }
  .brand span { display: none; }
}
