:root {
  --paper: #f6f4ef;
  --card: #ffffff;
  --ink: #22282b;
  --ink-2: #59636a;
  --ink-3: #8b949a;
  --line: #e5e2da;
  --line-2: #eeece6;
  --green: #2f5d50;
  --green-soft: #e8f0ec;
  --red: #b4553f;
  --red-soft: #f8ece8;
  --gold: #a8873f;
  --shadow: 0 1px 2px rgba(29, 38, 36, .04), 0 8px 24px rgba(29, 38, 36, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; background: #f2f0ea; padding: 1px 5px; border-radius: 3px; }

/* ── 登录 ── */
.login-mask { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(150deg, #eae7dc, #f7f5f0 55%, #e6ede8); z-index: 100; }
.login-card { width: 370px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 18px 60px rgba(30, 45, 40, .12); padding: 36px 34px 28px; text-align: center; }
.brand-seal { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 8px; background: var(--green); color: #fff; display: grid; place-items: center; font-size: 26px; font-family: "Songti SC", "STSong", serif; letter-spacing: 2px; }
.brand-seal.small { width: 34px; height: 34px; font-size: 18px; margin: 0; border-radius: 6px; flex: none; }
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: 3px; font-family: "Songti SC", "STSong", serif; }
.login-sub { margin: 4px 0 26px; color: var(--ink-3); font-size: 13px; letter-spacing: 1px; }
.login-card label { display: block; text-align: left; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 7px; background: #fcfbf8; outline: none; }
.login-card input:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.login-card .btn { margin-top: 16px; }
.login-err { color: var(--red); font-size: 12px; min-height: 18px; margin: 10px 0 0; }
.login-foot { color: var(--ink-3); font-size: 11px; line-height: 1.7; margin: 12px 0 0; }

/* ── 骨架 ── */
.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100vh; }
.side { background: #f0eee7; border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 22px 14px 18px; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; }
.side-brand b { display: block; font-size: 15px; letter-spacing: 2px; font-family: "Songti SC", "STSong", serif; }
.side-brand em { display: block; font-style: normal; font-size: 11px; color: var(--ink-3); letter-spacing: 2px; }
.nav-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 14px; border-radius: 7px; color: var(--ink-2); margin-bottom: 4px; font-size: 13.5px; }
.nav-item:hover { background: #e8e6de; }
.nav-item.active { background: var(--green); color: #fff; font-weight: 600; }
.side-foot { margin-top: auto; padding: 0 8px; }
.db-hint { font-size: 11px; color: var(--ink-3); line-height: 1.6; border-top: 1px solid var(--line); padding-top: 14px; margin-bottom: 8px; }
.text-btn { border: 0; background: transparent; color: var(--ink-3); font-size: 12px; padding: 4px 0; }
.text-btn:hover { color: var(--red); }

.main { min-width: 0; padding: 0 30px 60px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 26px 0 18px; }
.topbar h2 { margin: 0; font-size: 21px; letter-spacing: 1px; }
.topbar p { margin: 2px 0 0; color: var(--ink-3); font-size: 12.5px; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.stamp { font-size: 11.5px; color: var(--ink-3); }
.btn { border: 1px solid var(--line); background: #fff; padding: 7px 14px; border-radius: 7px; font-size: 13px; }
.btn:hover { border-color: var(--green); color: var(--green); }
.btn.primary { border-color: var(--green); background: var(--green); color: #fff; }
.btn.primary:hover { background: #264c42; color: #fff; }
.btn.block { width: 100%; padding: 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.notice { background: #fbf7ea; border: 1px solid #ede3c8; color: #7a6738; border-radius: 8px; padding: 9px 14px; font-size: 12px; margin-bottom: 20px; line-height: 1.7; }

/* ── 卡片 / KPI ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 17px; box-shadow: var(--shadow); }
.kpi .lab { font-size: 12px; color: var(--ink-3); letter-spacing: .5px; }
.kpi .val { font-size: 27px; font-weight: 650; line-height: 1.35; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 11.5px; color: var(--ink-3); }
.kpi .sub b { color: var(--green); font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-head .desc { font-size: 11.5px; color: var(--ink-3); }
.card-body { padding: 16px 18px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; }
.two-col > .card { display: flex; flex-direction: column; }
.two-col > .card > .card-body { flex: 1; }
.chart-body { display: flex; align-items: center; }
@media (max-width: 1080px) { .two-col { grid-template-columns: 1fr; } }

/* ── 图表 ── */
/* 让 SVG 按 viewBox 比例自动算高度；写死 height 会让 meet 缩放后上下留白。 */
.chart { width: 100%; height: auto; aspect-ratio: 720 / 190; display: block; }
.chart .grid { stroke: var(--line-2); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font-size: 10px; }
.chart .bar-new { fill: #9db9ae; }
.chart .bar-active { fill: var(--green); }
.legend { display: flex; gap: 16px; font-size: 11.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* ── 表格 ── */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar input[type=text], .toolbar select { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 7px 11px; outline: none; font-size: 13px; }
.toolbar input[type=text] { width: 260px; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--green); }
.toolbar .spacer { flex: 1; }
.toolbar .count { font-size: 12px; color: var(--ink-3); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
th { font-size: 11.5px; color: var(--ink-3); font-weight: 600; background: #faf9f5; letter-spacing: .3px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--green); }
th .arrow { color: var(--green); }
tbody tr:hover { background: #faf9f5; }
tbody tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; }
.uid { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--ink-2); cursor: pointer; }
.uid:hover { color: var(--green); text-decoration: underline; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11px; line-height: 1.7; border: 1px solid transparent; }
.badge.openid { background: var(--green-soft); color: var(--green); border-color: #d3e4db; }
.badge.device { background: #f2efe7; color: #8a7550; border-color: #e8dfc9; }
.badge.other { background: #f2f2f2; color: #777; }
.badge.muted { background: #f4f3f0; color: var(--ink-3); }
.tone { white-space: normal; min-width: 220px; line-height: 1.5; }
.rate-cell { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.bar-track { flex: 1; height: 6px; background: #efede7; border-radius: 4px; overflow: hidden; min-width: 60px; }
.bar-fill { height: 100%; background: var(--green); border-radius: 4px; }
.bar-fill.warm { background: var(--gold); }
.rate-num { font-size: 11.5px; color: var(--ink-2); width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line-2); font-size: 12.5px; color: var(--ink-2); }
.pager .spacer { flex: 1; }
.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); font-size: 13px; line-height: 1.9; }
.empty b { color: var(--ink-2); }

/* ── 抽屉 ── */
.drawer-mask { position: fixed; inset: 0; background: rgba(25, 32, 30, .32); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(660px, 94vw); background: var(--paper); z-index: 41; box-shadow: -12px 0 40px rgba(20, 30, 25, .16); display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 20px 24px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 17px; }
.drawer-head p { margin: 2px 0 0; font-size: 11.5px; color: var(--ink-3); font-family: ui-monospace, monospace; word-break: break-all; }
.icon-btn { border: 0; background: #f2f1ec; width: 28px; height: 28px; border-radius: 6px; color: var(--ink-2); }
.icon-btn:hover { background: #e7e5de; }
.drawer-body { overflow-y: auto; padding: 20px 24px 50px; }
.dsec { background: #fff; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 14px; overflow: hidden; }
.dsec > h4 { margin: 0; padding: 11px 16px; font-size: 13px; border-bottom: 1px solid var(--line-2); background: #faf9f5; }
.dsec .inner { padding: 14px 16px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 18px; }
.kv div { min-width: 0; }
.kv .k { font-size: 11px; color: var(--ink-3); }
.kv .v { font-size: 13.5px; font-variant-numeric: tabular-nums; word-break: break-all; }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 8px; }
.ach { border: 1px solid var(--line-2); border-radius: 7px; padding: 8px 10px; background: #fbfaf7; opacity: .62; }
.ach.done { opacity: 1; border-color: #cfe0d7; background: var(--green-soft); }
.ach .n { font-size: 12.5px; font-weight: 600; }
.ach .d { font-size: 11px; color: var(--ink-3); line-height: 1.5; margin-top: 2px; }
.ach .p { font-size: 10.5px; color: var(--green); margin-top: 4px; }
.group-title { font-size: 12px; color: var(--ink-2); font-weight: 600; margin: 14px 0 7px; }
.group-title:first-child { margin-top: 0; }
details summary { cursor: pointer; font-size: 12.5px; color: var(--green); padding: 4px 0; }
details pre { background: #f7f5f0; border: 1px solid var(--line-2); border-radius: 6px; padding: 12px; font-size: 11px; line-height: 1.6; overflow: auto; max-height: 340px; }
.tone-list { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.tone-chip { background: var(--green-soft); color: #2f5d50; border: 1px solid #d5e5dc; padding: 2px 8px; border-radius: 4px; font-size: 11.5px; }
.tone-chip.unknown { background: var(--red-soft); color: var(--red); border-color: #eed9d1; }
.scenario-row { border-bottom: 1px dashed var(--line-2); padding: 8px 0; }
.scenario-row:last-child { border-bottom: 0; }
.scenario-row .h { font-size: 12.5px; }
.scenario-row .h b { font-weight: 600; }
.scenario-row .h span { color: var(--ink-3); font-size: 11.5px; margin-left: 8px; }
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: #26332e; color: #fff; padding: 9px 18px; border-radius: 7px; font-size: 12.5px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.18); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 12px; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px; }
  .side-brand { padding: 0; }
  .side nav { display: flex; gap: 4px; flex: 1; }
  .nav-item { width: auto; margin: 0; padding: 7px 9px; font-size: 12px; }
  .side-foot { margin: 0; padding: 0; }
  .db-hint { display: none; }
  .main { padding: 0 14px 40px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  table { display: block; overflow-x: auto; }
}
