/* ==========================================================================
   VisitStat 设计系统
   --------------------------------------------------------------------------
   零依赖、纯手写 CSS。结构：
   1. 主题令牌（亮/暗）  2. 基础重置  3. 排版  4. 布局外壳
   5. 组件（卡片/按钮/表单/表格/徽章/弹层/toast/骨架屏）
   6. 图表样式  7. 响应式三档
   ========================================================================== */

/* ---------- 1. 主题令牌 ---------- */

:root,
[data-theme='light'] {
  color-scheme: light;

  /* 表面层级：0 最底、3 最浮起 */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e6e9ee;

  --text: #16191d;
  --text-2: #4a5260;
  --text-3: #737c8b;

  --border: #dce0e6;
  --border-strong: #c3c9d3;

  /* 品牌主色：靛蓝，与数据工具气质匹配，非渐变 */
  --accent: #3b5bdb;
  --accent-hover: #2f4bc4;
  --accent-soft: #e8ecfd;
  --accent-text: #ffffff;

  /* 语义色 */
  --up: #0f8a5f;
  --down: #c8372d;
  --neutral: #737c8b;
  --warn: #a8690b;
  --warn-soft: #fdf3e0;
  --danger: #c8372d;
  --danger-soft: #fdeceb;
  --ok: #0f8a5f;
  --ok-soft: #e6f5ef;

  /* 图表分类色板（8 色，色相均匀分布，含色盲友好间距） */
  --c1: #3b5bdb;
  --c2: #0f8a5f;
  --c3: #c77d0a;
  --c4: #8e4ec6;
  --c5: #1c7ed6;
  --c6: #c8372d;
  --c7: #0c8599;
  --c8: #8a6d3b;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-2: 0 4px 12px rgba(16, 24, 40, 0.1);
  --shadow-3: 0 12px 32px rgba(16, 24, 40, 0.16);

  /* 间距刻度（4px 基准） */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;
  --s8: 32px;
  --s10: 40px;

  /* 字号刻度 */
  --f-xs: 11px;
  --f-sm: 12px;
  --f-md: 13px;
  --f-base: 14px;
  --f-lg: 16px;
  --f-xl: 20px;
  --f-2xl: 26px;
  --f-3xl: 32px;

  --radius: 8px;
  --radius-sm: 5px;
  --radius-lg: 12px;

  --sidebar-w: 208px;
  --topbar-h: 56px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Mono', Menlo, Consolas,
    'Liberation Mono', monospace;
}

[data-theme='dark'] {
  color-scheme: dark;

  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c232c;
  --surface-3: #252d38;

  --text: #e8edf3;
  --text-2: #a8b3c1;
  --text-3: #7f8b9b;

  --border: #2b3441;
  --border-strong: #3d4857;

  --accent: #6b8cff;
  --accent-hover: #859fff;
  --accent-soft: #1e2a4d;
  --accent-text: #0e1116;

  --up: #3ddc97;
  --down: #ff6b5e;
  --neutral: #7f8b9b;
  --warn: #f0b429;
  --warn-soft: #33280f;
  --danger: #ff6b5e;
  --danger-soft: #3a1b1a;
  --ok: #3ddc97;
  --ok-soft: #10312a;

  --c1: #6b8cff;
  --c2: #3ddc97;
  --c3: #f0b429;
  --c4: #b57bff;
  --c5: #4dabf7;
  --c6: #ff6b5e;
  --c7: #22b8cf;
  --c8: #c9a227;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-3: 0 12px 32px rgba(0, 0, 0, 0.6);
}

/* ---------- 2. 基础重置 ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--f-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 数字统一等宽 + 表格数字对齐：数据工具的关键细节 */
.num,
.stat-value,
table td.num,
.vs-hbar-num,
.vs-legend-val,
.vs-axis,
.vs-heat-val,
.vs-funnel-count,
.vs-donut-center,
.kpi-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

/* 焦点可见：键盘可达的硬性要求 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* 跳转链接（屏幕阅读器/键盘用户） */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 999;
  padding: var(--s2) var(--s4);
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 0 0 var(--radius) 0;
  font-size: var(--f-md);
}
.skip-link:focus {
  left: 0;
}

/* ---------- 3. 排版 ---------- */

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: var(--f-xl);
}
h2 {
  font-size: var(--f-lg);
}
h3 {
  font-size: var(--f-base);
}

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

code,
kbd,
pre {
  font-family: var(--font-mono);
  font-size: var(--f-md);
}

/* ---------- 4. 布局外壳 ---------- */

#app {
  min-height: 100%;
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s4) var(--s3);
  gap: var(--s4);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 0 var(--s2) var(--s3);
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-size: var(--f-sm);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand-name {
  font-size: var(--f-base);
  font-weight: 650;
  letter-spacing: -0.02em;
}
.brand-sub {
  font-size: var(--f-xs);
  color: var(--text-3);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-group-label {
  padding: var(--s3) var(--s3) var(--s1);
  font-size: var(--f-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}

.nav a {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 7px var(--s3);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: var(--f-md);
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.nav a[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 550;
}

.nav-icon {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  opacity: 0.85;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: var(--s3);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

/* 主区 */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: var(--topbar-h);
  padding: 0 var(--s5);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
}

.topbar-title {
  font-size: var(--f-base);
  font-weight: 600;
  white-space: nowrap;
}

.topbar-spacer {
  flex: 1 1 auto;
  min-width: var(--s2);
}

.content {
  padding: var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: var(--f-xl);
}
.page-desc {
  margin: var(--s1) 0 0;
  color: var(--text-3);
  font-size: var(--f-md);
}

/* 网格 */
.grid {
  display: grid;
  gap: var(--s4);
}
/* ≥1280px 三栏，768–1280 两栏，<768 单栏 */
.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
/* 主内容 + 侧栏（宽屏 2fr/1fr） */
.grid-split {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}
.span-2 {
  grid-column: span 2;
}
.span-full {
  grid-column: 1 / -1;
}

/* ---------- 5. 组件 ---------- */

/* 卡片 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.card-title {
  font-size: var(--f-md);
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.card-sub {
  font-size: var(--f-xs);
  color: var(--text-3);
  margin: 2px 0 0;
}

.card-body {
  padding: var(--s4);
  min-width: 0;
  flex: 1 1 auto;
}
.card-body.flush {
  padding: 0;
}
.card-body.tight {
  padding: var(--s3);
}

/* KPI 卡片 */
.kpi {
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  min-width: 0;
}
.kpi-label {
  font-size: var(--f-xs);
  font-weight: 550;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: var(--s1);
}
.kpi-value {
  font-size: var(--f-2xl);
  font-weight: 640;
  letter-spacing: -0.025em;
  line-height: 1.15;
  color: var(--text);
  overflow-wrap: anywhere;
}
.kpi-foot {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--f-sm);
  color: var(--text-3);
  flex-wrap: wrap;
}

/* 环比箭头 */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: var(--f-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
}
.delta-up {
  color: var(--up);
  background: var(--ok-soft);
}
.delta-down {
  color: var(--down);
  background: var(--danger-soft);
}
.delta-flat {
  color: var(--neutral);
  background: var(--surface-2);
}
/* 跳出率上升是坏事：反转语义色 */
.delta-inverse.delta-up {
  color: var(--down);
  background: var(--danger-soft);
}
.delta-inverse.delta-down {
  color: var(--up);
  background: var(--ok-soft);
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  padding: 6px 12px;
  min-height: 30px;
  font-family: inherit;
  font-size: var(--f-md);
  font-weight: 550;
  line-height: 1.3;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  text-decoration: none;
}
.btn:hover:not(:disabled) {
  background: var(--surface-2);
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}
.btn-sm {
  padding: 3px 8px;
  min-height: 24px;
  font-size: var(--f-sm);
}
.btn-block {
  width: 100%;
}
.btn-icon {
  padding: 5px;
  min-height: 28px;
  min-width: 28px;
}

/* 分段控件（时间范围、interval 切换） */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 1px;
  flex-wrap: nowrap;
}
.segmented button {
  padding: 4px 10px;
  font-family: inherit;
  font-size: var(--f-sm);
  font-weight: 550;
  color: var(--text-2);
  background: transparent;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.segmented button:hover {
  color: var(--text);
  background: var(--surface-3);
}
.segmented button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* 表单 */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  min-width: 0;
}
.field > label,
.field-label {
  font-size: var(--f-sm);
  font-weight: 550;
  color: var(--text-2);
}
.field-hint {
  font-size: var(--f-xs);
  color: var(--text-3);
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='date'],
input[type='search'],
select,
textarea {
  width: 100%;
  min-height: 32px;
  padding: 5px 9px;
  font-family: inherit;
  font-size: var(--f-md);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder,
textarea::placeholder {
  color: var(--text-3);
}
input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-2);
  color: var(--text-3);
  cursor: not-allowed;
}
select {
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}
textarea {
  min-height: 64px;
  resize: vertical;
  line-height: 1.5;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--f-md);
  cursor: pointer;
}
.checkbox input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-error {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: var(--f-md);
}
.form-error:empty {
  display: none;
}

/* 工具栏 */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}
.toolbar-gap {
  flex: 1 1 auto;
}

/* 表格 */
.table-wrap {
  overflow-x: auto;
  min-width: 0;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--f-md);
}
table.data th,
table.data td {
  padding: 8px var(--s3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--f-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
table.data tbody tr:hover {
  background: var(--surface-2);
}
table.data tbody tr:last-child td {
  border-bottom: 0;
}
table.data td.num,
table.data th.num {
  text-align: right;
}
table.data td.wrap {
  white-space: normal;
  min-width: 160px;
  max-width: 420px;
  overflow-wrap: anywhere;
}

/* 可排序表头 */
th.sortable {
  cursor: pointer;
  user-select: none;
}
th.sortable:hover {
  color: var(--text);
}
th.sortable::after {
  content: '';
  display: inline-block;
  width: 0;
  margin-left: 4px;
  border: 4px solid transparent;
  vertical-align: middle;
}
th.sortable[data-dir='asc']::after {
  border-bottom-color: var(--accent);
  margin-bottom: 3px;
}
th.sortable[data-dir='desc']::after {
  border-top-color: var(--accent);
  margin-top: 3px;
}

/* 徽章 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: var(--f-xs);
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-ok {
  color: var(--ok);
  background: var(--ok-soft);
}
.badge-warn {
  color: var(--warn);
  background: var(--warn-soft);
}
.badge-danger {
  color: var(--danger);
  background: var(--danger-soft);
}
.badge-muted {
  color: var(--text-3);
  background: var(--surface-2);
}
.badge-accent {
  color: var(--accent);
  background: var(--accent-soft);
}

/* 等宽/截断文本 */
.mono {
  font-family: var(--font-mono);
  font-size: var(--f-sm);
}
.truncate {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: bottom;
}
.muted {
  color: var(--text-3);
}
.dim {
  color: var(--text-2);
}
.nowrap {
  white-space: nowrap;
}

/* 复制按钮组 */
.copy-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
}
.copy-row > .mono {
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px var(--s2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: nowrap;
}

/* 代码块 */
.code-block {
  margin: 0;
  padding: var(--s3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: var(--f-sm);
  line-height: 1.6;
  color: var(--text-2);
  white-space: pre;
  tab-size: 2;
}

/* 弹层 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--s4);
  background: rgba(9, 12, 17, 0.5);
  animation: fade-in 0.14s ease;
}
.modal {
  width: min(560px, 100%);
  max-height: min(86vh, 780px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  animation: pop-in 0.16s ease;
  overflow: hidden;
}
.modal.wide {
  width: min(760px, 100%);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s4);
  border-bottom: 1px solid var(--border);
}
.modal-title {
  margin: 0;
  font-size: var(--f-lg);
  font-weight: 600;
}
.modal-body {
  padding: var(--s4);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.99);
  }
}

/* toast */
.toast-stack {
  position: fixed;
  right: var(--s4);
  bottom: var(--s4);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  max-width: min(400px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: 9px var(--s3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  font-size: var(--f-md);
  color: var(--text);
  animation: toast-in 0.16s ease;
  pointer-events: auto;
}
.toast-ok {
  border-left-color: var(--ok);
}
.toast-err {
  border-left-color: var(--danger);
}
.toast-warn {
  border-left-color: var(--warn);
}
.toast-msg {
  flex: 1 1 auto;
  overflow-wrap: anywhere;
}
.toast-close {
  border: 0;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  font-size: var(--f-lg);
  line-height: 1;
  padding: 0 2px;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
}

/* 骨架屏 */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}
.sk-line {
  height: 10px;
  margin-bottom: var(--s2);
}
.sk-value {
  height: 26px;
  width: 62%;
  margin-bottom: var(--s2);
}
.sk-chart {
  height: 200px;
  width: 100%;
}
.sk-row {
  height: 14px;
  margin-bottom: 9px;
}

/* 空态 */
.vs-empty {
  margin: 0;
  padding: var(--s8) var(--s4);
  text-align: center;
  color: var(--text-3);
  font-size: var(--f-md);
  line-height: 1.7;
}
.vs-empty-sm {
  padding: var(--s3);
}

/* 错误/降级横幅 */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  font-size: var(--f-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.banner-warn {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 34%, transparent);
  color: var(--warn);
}
.banner-err {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 34%, transparent);
  color: var(--danger);
}

/* 分页 */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  padding: var(--s2) var(--s4);
  border-top: 1px solid var(--border);
  font-size: var(--f-sm);
  color: var(--text-3);
  flex-wrap: wrap;
}
.pager-btns {
  display: flex;
  align-items: center;
  gap: var(--s1);
}

/* 描述列表（设置页） */
.dl {
  display: grid;
  grid-template-columns: minmax(110px, auto) minmax(0, 1fr);
  gap: var(--s2) var(--s4);
  margin: 0;
  font-size: var(--f-md);
}
.dl dt {
  color: var(--text-3);
}
.dl dd {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* 实时脉冲 */
.pulse-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  flex: 0 0 auto;
}
.pulse-dot::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 1.9s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }
  70%,
  100% {
    transform: scale(3.2);
    opacity: 0;
  }
}
.realtime-value {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

/* ---------- 6. 图表 ---------- */

.vs-chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.vs-grid {
  stroke: var(--border);
  stroke-width: 1;
  shape-rendering: crispEdges;
}
.vs-axis {
  fill: var(--text-3);
  font-size: 10px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}
.vs-hit {
  cursor: crosshair;
}
.vs-hit:hover {
  fill: color-mix(in srgb, var(--accent) 12%, transparent);
}
.vs-bar {
  transition: fill-opacity 0.12s ease;
  cursor: default;
}
.vs-bar:hover {
  fill-opacity: 0.78;
}
.vs-donut-seg {
  transition: stroke-opacity 0.12s ease;
  cursor: default;
}
.vs-donut-seg:hover {
  stroke-opacity: 0.75;
}
.vs-donut {
  width: 132px;
  height: 132px;
  flex: 0 0 auto;
}
.vs-donut-center {
  fill: var(--text);
  font-size: 19px;
  font-weight: 650;
  font-family: var(--font);
}
.vs-donut-sub {
  fill: var(--text-3);
  font-size: 9px;
  font-family: var(--font);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.vs-donut-wrap {
  display: flex;
  align-items: center;
  gap: var(--s4);
  flex-wrap: wrap;
}
.vs-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 150px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: var(--f-sm);
}
.vs-legend li {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
}
.vs-legend i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex: 0 0 auto;
}
.vs-legend-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
}
.vs-legend-val {
  flex: 0 0 auto;
  color: var(--text-3);
  font-size: var(--f-xs);
}

/* 横条列表 */
.vs-hbar-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.vs-hbar-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2);
  margin-bottom: 3px;
}
.vs-hbar-label {
  font-size: var(--f-md);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
a.vs-hbar-label:hover {
  color: var(--accent);
}
.vs-hbar-num {
  font-size: var(--f-sm);
  font-weight: 600;
  color: var(--text-2);
  flex: 0 0 auto;
}
.vs-hbar-track {
  height: 5px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.vs-hbar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.18s ease;
}
.vs-hbar-foot {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  margin-top: 2px;
  font-size: var(--f-xs);
  color: var(--text-3);
}

/* 热力图 */
.vs-heat-scroll {
  overflow-x: auto;
  min-width: 0;
}
.vs-heat {
  display: block;
  height: auto;
}
.vs-heat-val {
  fill: var(--text);
  font-size: 9.5px;
  font-weight: 550;
  font-family: var(--font);
  pointer-events: none;
}
.vs-heat-label {
  font-size: 10px;
}

/* 漏斗 */
.vs-funnel {
  display: block;
  width: 100%;
  height: auto;
}
.vs-funnel-name {
  fill: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  pointer-events: none;
}
.vs-funnel-count {
  fill: var(--accent-text);
  font-size: 11px;
  font-family: var(--font);
  opacity: 0.85;
  pointer-events: none;
}
.vs-funnel-rate {
  fill: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}

/* tooltip（图表统一） */
.vs-tip {
  position: fixed;
  z-index: 300;
  pointer-events: none;
  padding: 6px 9px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  font-size: var(--f-sm);
  color: var(--text);
  white-space: pre;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.1s ease;
}
.vs-tip.show {
  opacity: 1;
}

/* ---------- 登录页 ---------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s5);
  background: var(--bg);
}
.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: var(--s6);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.auth-title {
  font-size: var(--f-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
}
.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: var(--s1);
}
.auth-tabs button {
  flex: 1 1 0;
  padding: var(--s2) var(--s3);
  font-family: inherit;
  font-size: var(--f-md);
  font-weight: 550;
  color: var(--text-3);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.auth-tabs button:hover {
  color: var(--text);
}
.auth-tabs button[aria-selected='true'] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
/* hidden 属性优先级必须压过 display:flex，否则双面板同时可见 */
.auth-form[hidden] {
  display: none;
}
.auth-foot {
  font-size: var(--f-xs);
  color: var(--text-3);
  text-align: center;
  line-height: 1.6;
}

/* 主题切换按钮 */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 5px var(--s2);
  font-family: inherit;
  font-size: var(--f-sm);
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* 用户菜单 */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 3px var(--s2) 3px 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: var(--f-sm);
  color: var(--text-2);
  max-width: 220px;
}
.user-avatar {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-size: var(--f-xs);
  font-weight: 700;
  text-transform: uppercase;
}
.user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* 步骤编辑器（漏斗） */
.step-list {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.step-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
}
.step-idx {
  width: 20px;
  flex: 0 0 auto;
  font-size: var(--f-sm);
  color: var(--text-3);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- 7. 响应式三档 ---------- */

/* < 1280px：两栏 */
@media (max-width: 1279px) {
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-split {
    grid-template-columns: minmax(0, 1fr);
  }
  .span-2 {
    grid-column: span 1;
  }
  :root {
    --sidebar-w: 176px;
  }
}

/* < 960px：侧边栏收成顶部横向滚动导航 */
@media (max-width: 959px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: var(--s3);
    padding: var(--s2) var(--s3);
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
  }
  .brand {
    border-bottom: 0;
    padding: 0;
    flex: 0 0 auto;
  }
  .brand-sub {
    display: none;
  }
  .nav {
    flex-direction: row;
    gap: var(--s1);
  }
  .nav-group-label {
    display: none;
  }
  .nav a {
    white-space: nowrap;
    padding: 5px var(--s2);
  }
  .sidebar-foot {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
    flex-direction: row;
    flex: 0 0 auto;
    margin-left: auto;
  }
  .topbar {
    padding: 0 var(--s4);
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: wrap;
    padding-top: var(--s2);
    padding-bottom: var(--s2);
  }
  .content {
    padding: var(--s4);
    gap: var(--s4);
  }
}

/* < 768px：单栏 */
@media (max-width: 767px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: minmax(0, 1fr);
  }
  .span-2 {
    grid-column: span 1;
  }
  .content {
    padding: var(--s3);
    gap: var(--s3);
  }
  .kpi-value {
    font-size: var(--f-xl);
  }
  .card-head {
    padding: var(--s2) var(--s3);
  }
  .card-body {
    padding: var(--s3);
  }
  .topbar-title {
    display: none;
  }
  .user-chip {
    max-width: 140px;
  }
  .modal {
    max-height: 92vh;
  }
  .dl {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s1);
  }
  .dl dd {
    margin-bottom: var(--s2);
  }
  .toast-stack {
    left: var(--s3);
    right: var(--s3);
    bottom: var(--s3);
    max-width: none;
  }
  /* 表格在窄屏隐藏次要列 */
  table.data .hide-sm {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 打印：去掉交互外壳，保留数据 */
@media print {
  .sidebar,
  .topbar,
  .toast-stack,
  .btn {
    display: none !important;
  }
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }
  body {
    background: #fff;
  }
}
