:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: rgba(255, 255, 255, .08);
  --text: #f2f5f8;
  --text-2: #9aa4b2;
  --text-3: #6b7684;
  --accent: #4da3ff;
  --success: #3dd68c;
  --warn: #ffb020;
  --danger: #ff5c5c;
  --series-1: #3987e5;
  --series-2: #d95926;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono { font-family: "SF Mono", Menlo, "Roboto Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.accent { color: var(--accent); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ── 布局 ─────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px 22px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.nav-toggle { display: none; }

.nav-toggle-label {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.logo {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #4da3ff, #2e6be6);
  color: #06121f;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-name { font-size: 16px; font-weight: 700; }
.brand-sub { color: var(--text-3); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 4px; padding: 18px 0; flex: 1; min-height: 0; overflow-y: auto; }
.nav a {
  color: var(--text-2);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: rgba(77, 163, 255, .14); color: var(--accent); font-weight: 600; }
.nav-section-title {
  margin: 14px 12px 4px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
}

.nav a.nav-sub {
  padding: 6px 12px 6px 26px;
  font-size: 12px;
  color: var(--text-3);
}

.nav a.nav-sub.active {
  color: var(--accent);
  font-weight: 600;
}

.logout { margin-top: auto; }

.logout button {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-3);
  font-size: 13px;
  cursor: pointer;
}
.logout button:hover { color: var(--text); border-color: var(--text-3); }

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 30px 60px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}
.page-title { font-size: 24px; font-weight: 700; }
.page-sub { color: var(--text-3); font-size: 13px; margin-top: 3px; }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── 卡片 / 统计 ──────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.stat-label { color: var(--text-3); font-size: 12px; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1.2; }
.stat-value.small { font-size: 18px; }
.stat-value .unit { font-size: 14px; color: var(--text-3); font-weight: 400; margin-left: 3px; }
.stat-sub { color: var(--text-3); font-size: 12px; margin-top: 5px; }
.stat-value.ok { color: var(--success); }
.stat-value.warn { color: var(--warn); }

/* ── 图表 ─────────────────────────────────────────────── */
.chart-card { margin-bottom: 16px; }
.chart-scroll { overflow-x: auto; }

.legend { display: flex; gap: 16px; align-items: center; }
.legend-item { color: var(--text-2); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-dot.matched { background: var(--series-1); }
.legend-dot.unmatched { background: var(--series-2); }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 250px;
  min-width: 700px;
  padding: 10px 8px 26px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
}
.bar-col {
  flex: 1;
  min-width: 16px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  position: relative;
}
.bar-stack {
  width: 100%;
  max-width: 26px;
  min-height: 0;
  display: flex;
  flex-direction: column-reverse;
  border-radius: 4px 4px 0 0;
  overflow: hidden;
}
.bar-seg { width: 100%; flex: none; }
.bar-seg.matched { background: var(--series-1); }
.bar-seg.unmatched { background: var(--series-2); }
.bar-seg.gap { border-top: 2px solid var(--surface); box-sizing: border-box; }
.bar-label {
  position: absolute;
  bottom: -21px;
  left: 50%;
  transform: translateX(-50%);
  height: 14px;
  line-height: 14px;
  color: var(--text-3);
  font-size: 10px;
  white-space: nowrap;
}
.chart-note { color: var(--text-3); font-size: 11px; margin-top: 10px; }

.svg-chart { width: 100%; min-width: 700px; display: block; }
.svg-chart .grid { stroke: var(--border); stroke-width: 1; }
.svg-chart .axis { fill: var(--text-3); font-size: 11px; }
.svg-chart .line {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.svg-chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }

.hbar-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.hbar-label {
  width: 110px;
  flex: none;
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hbar-track {
  flex: 1;
  height: 10px;
  background: var(--surface-2);
  border-radius: 5px;
  overflow: hidden;
}
.hbar-fill { height: 100%; background: var(--series-1); border-radius: 5px; }
.hbar-count { width: 36px; flex: none; text-align: right; color: var(--text-3); font-size: 12px; }

.viz-table { margin: 18px 0 40px; }
.viz-table summary { color: var(--text-2); font-size: 13px; cursor: pointer; margin-bottom: 10px; }

.grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.link { font-size: 13px; }

/* ── 表格 ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th, .table td {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th {
  color: var(--text-3);
  font-weight: 500;
  font-size: 12px;
  white-space: nowrap;
}
.table tr:last-child td { border-bottom: none; }
.table.compact th, .table.compact td { padding: 8px 8px; font-size: 12.5px; }

.empty {
  color: var(--text-3);
  padding: 26px 4px;
  text-align: center;
  font-size: 13px;
}
.empty.large { padding: 56px 4px; }

/* ── 状态 / 键值 ──────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.ok { background: rgba(61, 214, 140, .12); color: var(--success); }
.badge.bad { background: rgba(255, 92, 92, .12); color: var(--danger); }

.kv { margin: 0; }
.kv dt { color: var(--text-3); font-size: 12px; margin-top: 10px; }
.kv dt:first-child { margin-top: 0; }
.kv dd { margin: 2px 0 0; font-size: 13px; }

/* ── 表单 ─────────────────────────────────────────────── */
.filter {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filter input[type="text"] { flex: 1; min-width: 220px; }
.filter select { min-width: 130px; }
.count { margin-left: auto; font-size: 12px; }

input[type="text"], input[type="password"], select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 9px 11px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { width: 100%; resize: vertical; }
input[readonly] { color: var(--text-3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--text-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.danger { background: rgba(255, 92, 92, .12); border-color: rgba(255, 92, 92, .4); color: var(--danger); }
.btn.wide { width: 100%; margin-top: 16px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--text-2); font-size: 12px; }
.field input, .field select { width: 100%; }

.model-form { margin-top: 4px; }
.model-form > .field { margin-top: 14px; }
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
}
.form-actions .muted { font-size: 12px; }
.form-error {
  background: rgba(255, 92, 92, .1);
  border: 1px solid rgba(255, 92, 92, .35);
  color: #ff9b9b;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.flashes { margin-bottom: 14px; }
.flash {
  background: rgba(61, 214, 140, .1);
  border: 1px solid rgba(61, 214, 140, .3);
  color: var(--success);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 8px;
}
.danger-zone {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.note { font-size: 12px; margin-top: 12px; }
.narrow { max-width: 560px; }

.pager { display: flex; gap: 10px; justify-content: flex-end; padding-top: 14px; }

/* ── 登录 ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 34px 30px 26px;
  text-align: center;
}
.login-logo {
  width: 58px;
  height: 58px;
  margin: 0 auto;
  border-radius: 16px;
  background: linear-gradient(135deg, #4da3ff, #2e6be6);
  color: #06121f;
  font-size: 28px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card h1 { font-size: 22px; margin: 16px 0 2px; }
.login-sub { color: var(--text-3); font-size: 13px; margin: 0 0 22px; }
.login-card .field { text-align: left; }
.login-note { color: var(--text-3); font-size: 11.5px; margin: 16px 0 0; }
.login-icp { margin-top: 8px; }
.login-icp a { color: inherit; text-decoration: none; }

/* ── 响应式 ───────────────────────────────────────────── */
@media (max-width: 980px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .layout { display: block; }
  .sidebar {
    width: auto;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
  }
  .sidebar-head { padding-bottom: 12px; }
  .nav-toggle-label { display: inline-flex; margin-left: auto; }

  /* 手机上导航默认收起，点“菜单”再展开，避免分类链接把内容顶到屏幕外 */
  .nav {
    display: none;
    flex-direction: column;
    flex-wrap: nowrap;
    flex: none;
    padding: 10px 0 4px;
    max-height: 70vh;
    overflow-y: auto;
  }
  .nav-toggle:checked ~ .nav { display: flex; }
  .nav a { padding: 9px 10px; }
  .nav-section-title { margin-top: 10px; }

  .main { padding: 18px 16px 40px; }
  .cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1; text-align: center; }
  .card { padding: 14px; }
  .page-title { font-size: 21px; }
  .filter input[type="text"] { min-width: 100%; }
  .count { margin-left: 0; }
  .table th, .table td { padding: 8px 7px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
}

/* ── 用户详情：按天分组 ───────────────────────────────── */
.day-group { margin-bottom: 18px; }
.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 14px 0 8px;
}
.day-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
