/* ---------- 设计变量 ---------- */
:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --text: #1b1f27; --muted: #697386; --faint: #9aa3b2;
  --line: #e6e8ee; --line-strong: #d5d9e1;
  --accent: #4f5bd5; --accent-soft: #eef0fd; --accent-text: #3a45b8;
  --ok: #18794e; --ok-soft: #e7f6ee; --bad: #c4314b; --bad-soft: #fdecef; --warn: #a15c07; --warn-soft: #fdf3e2;
  --side: #14161c; --side-text: #a7adbb; --side-hover: #1f222b; --side-on: #262a35;
  --radius: 10px; --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --font: "Inter", -apple-system, "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1c2029; --text: #e8eaef; --muted: #9aa2b1; --faint: #6b7383;
    --line: #262a34; --line-strong: #333845;
    --accent: #8b95ff; --accent-soft: #23264a; --accent-text: #b5bbff;
    --ok: #4ccb8b; --ok-soft: #12291f; --bad: #ff7a8f; --bad-soft: #3a1820; --warn: #f2b45a; --warn-soft: #33260f;
    --side: #0b0d11; --side-text: #8d94a3; --side-hover: #151820; --side-on: #1d212b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- 框架：侧边栏 + 内容 ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand b { display: block; font-size: 15px; letter-spacing: .02em; }
.brand small { display: block; color: var(--side-text); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.logo { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #6d78ff, #4f5bd5 55%, #7c4dff); box-shadow: 0 4px 14px rgba(79, 91, 213, .45); }
.side nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: 11px; color: #626a7a; letter-spacing: .08em; padding: 14px 12px 6px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 8px; color: var(--side-text); font-size: 14px; }
.side nav a:hover { background: var(--side-hover); color: #e9ebf0; text-decoration: none; }
.side nav a.on { background: var(--side-on); color: #fff; box-shadow: inset 3px 0 0 #7c86ff; }
.side nav a.on .ico { color: #9aa3ff; }
.me { display: flex; align-items: center; gap: 8px; border-top: 1px solid #23262f; padding: 14px 6px 0; margin-top: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #2a2f3d; color: #dfe3ff; display: grid; place-items: center; font-weight: 600; flex: none; }
.me-text { flex: 1; min-width: 0; line-height: 1.3; }
.me-text b { display: block; color: #e9ebf0; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { color: var(--side-text); font-size: 11px; }
.me form { margin: 0; }
.icon-btn { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--side-text); cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--side-hover); color: #fff; text-decoration: none; }

main { min-width: 0; padding: 28px 36px 64px; max-width: 1360px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 32px 0 12px; display: flex; align-items: center; gap: 8px; }
h2::before { content: ""; width: 4px; height: 15px; border-radius: 2px; background: var(--accent); }
p { margin: 8px 0; }

.flash { display: flex; align-items: center; gap: 8px; background: var(--ok-soft); color: var(--ok); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 18px; font-weight: 500; }

/* ---------- 指标卡片 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card .k { color: var(--muted); font-size: 13px; }
.card .v { font-size: 24px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; line-height: 1.25; word-break: break-word; }
.card .s { color: var(--muted); font-size: 12px; margin-top: 6px; }
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.kpi.accent .kpi-ico { background: var(--accent-soft); color: var(--accent); }
.kpi.ok .kpi-ico { background: var(--ok-soft); color: var(--ok); }
.kpi.bad .kpi-ico { background: var(--bad-soft); color: var(--bad); }
.kpi.warn .kpi-ico { background: var(--warn-soft); color: var(--warn); }
.kpi.hero { background: linear-gradient(135deg, #4f5bd5, #6a4fd8); border: 0; color: #fff; }
.kpi.hero .k, .kpi.hero .s, .kpi.hero .s a { color: rgba(255, 255, 255, .78); }
.kpi.hero .kpi-ico { background: rgba(255, 255, 255, .16); color: #fff; }
.card.small .v { font-size: 18px; }

/* ---------- 图表 ---------- */
.chart-card { padding: 18px 18px 10px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart { width: 100%; height: auto; display: block; }
.chart .bar-in, .chart-legend .bar-in { fill: var(--accent); background: var(--accent); }
.chart .bar-out, .chart-legend .bar-out { fill: #c9cdea; background: #c9cdea; }
.chart .line { fill: none; stroke: var(--ok); stroke-width: 2.2; }
.chart .dot { fill: var(--surface); stroke: var(--ok); stroke-width: 2; }
.chart-legend .line { background: var(--ok); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--faint); font-size: 11px; font-family: var(--font); }
@media (prefers-color-scheme: dark) { .chart .bar-out, .chart-legend .bar-out { fill: #3a3f5c; background: #3a3f5c; } }

/* ---------- 表格 ---------- */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; background: var(--surface-2); letter-spacing: .02em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td .num, .num { display: block; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th .num { display: block; text-align: right; }
tr.total td { font-weight: 600; }
tr.dim td { color: var(--faint); }
.empty { color: var(--faint); text-align: center; padding: 32px; }
td a { font-weight: 500; }

/* ---------- 标签与颜色 ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted); white-space: nowrap; border: 1px solid var(--line); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.muted { opacity: .8; }
.pos { color: var(--ok); } .neg { color: var(--bad); }
.muted { color: var(--muted); }

/* ---------- 工具栏与表单 ---------- */
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.period { margin: 0; }
.period label { display: inline-flex; align-items: center; gap: 0; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.period label span { padding: 0 10px; color: var(--muted); font-size: 13px; border-right: 1px solid var(--line); align-self: stretch; display: grid; place-items: center; background: var(--surface-2); }
.period input { border: 0; border-radius: 0; box-shadow: none; }
form.inline { display: inline; margin: 0; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.grid-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.grid-form .full { grid-column: 1 / -1; }
input, select, textarea { font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); min-width: 0; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button { font: inherit; font-size: 14px; font-weight: 500; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; transition: filter .15s, background .15s; }
button:hover { filter: brightness(1.08); }
button.ghost { background: var(--surface); color: var(--accent-text); border-color: var(--line-strong); }
button.ghost:hover { background: var(--accent-soft); filter: none; }
button.link { border: 0; background: none; color: var(--accent-text); padding: 0; font-weight: 500; }
button.link:hover { text-decoration: underline; filter: none; }
button.danger { background: var(--bad); border-color: var(--bad); }
a.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 500; box-shadow: var(--shadow); }
a.btn:hover { background: var(--accent-soft); text-decoration: none; }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.spacer { flex: 1; }

.note { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; padding: 12px 16px; margin: 12px 0 18px; font-size: 13.5px; color: var(--text); }
.note.warn { border-left-color: var(--warn); background: var(--warn-soft); border-color: transparent; border-left-color: var(--warn); }
.note.bad { border-left-color: var(--bad); background: var(--bad-soft); border-color: transparent; border-left-color: var(--bad); }
details { margin-top: 12px; }
details summary { cursor: pointer; color: var(--accent-text); font-weight: 500; padding: 6px 0; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; margin: 0; box-shadow: var(--shadow); }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-word; }

/* ---------- 登录页 ---------- */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, rgba(109, 120, 255, .22), transparent 60%),
              radial-gradient(900px 500px at 110% 110%, rgba(124, 77, 255, .18), transparent 60%), var(--bg); }
.login { width: 100%; max-width: 380px; }
.login .brand { justify-content: center; color: var(--text); padding-bottom: 22px; }
.login .brand small { color: var(--muted); }
.login form { display: flex; flex-direction: column; gap: 14px; background: var(--surface); padding: 28px; border-radius: 16px; border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
.login h1 { font-size: 20px; }
.login .sub { color: var(--muted); margin: -8px 0 4px; font-size: 13px; }
.login label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.login button { padding: 10px; margin-top: 4px; }
.login .foot { text-align: center; color: var(--faint); font-size: 12px; margin-top: 16px; }

/* ---------- 手机 ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 6px; }
  .brand { padding: 0 6px 0 2px; flex: 1; }
  .brand small { display: none; }
  .logo { width: 30px; height: 30px; }
  .me { order: 2; border: 0; padding: 0; margin: 0; }
  .me-text, .avatar { display: none; }
  .side nav { order: 3; flex-basis: 100%; flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 2px; scrollbar-width: none; }
  .side nav::-webkit-scrollbar { display: none; }
  .nav-group { display: none; }
  .side nav a { white-space: nowrap; padding: 6px 10px; font-size: 13px; }
  .side nav a.on { box-shadow: inset 0 -2px 0 #7c86ff; }
  main { padding: 18px 16px 48px; }
  h1 { font-size: 20px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 12px 14px; }
  .card .v { font-size: 18px; }
  th, td { padding: 8px 10px; white-space: nowrap; }
  dl.kv { grid-template-columns: 1fr; gap: 2px 0; }
  dl.kv dd { margin-bottom: 8px; }
}
@media (max-width: 420px) { .cards { grid-template-columns: 1fr; } }
