/* ==========================================================================
   Baby ActiveAI · Admin 管理中心样式
   --------------------------------------------------------------------------
   结构索引：
   1. Design Tokens（:root 统一 Token + Legacy 别名，单一事实来源）
   2. Base / 现有页面规则（布局 / 卡片 / 图表 / 表格 / 筛选 / 分页 / 登录 / 详情 / Analytics / Diagnostics）
   3. RESPONSIVE BREAKPOINTS（统一断点注释区，见文件末尾）
   4. DESIGN SYSTEM（Phase 1 公共基础设施：.ui-* 组件 / Layout / Responsive / Legacy Compatibility）
   ========================================================================== */

:root {
  /* ================= 1. Design Tokens（统一 Design System） ================= */
  /* ---------- Color ---------- */
  --bg: #F7F7F5;                 /* 页面暖白背景 */
  --surface: #FFFFFF;            /* 白色 Surface */
  --surface-subtle: #FAF9F7;     /* 浅暖灰 Surface（表头 / hover / 次级区块） */
  --border: #E8E5E0;             /* 常规边框 */
  --border-strong: #D8D4CD;      /* 强调边框 / 可交互控件边框 */
  --text-primary: #28241F;       /* 正文主色（深灰） */
  --text-secondary: #70685F;     /* 次级文字 */
  --text-tertiary: #9B938A;      /* 弱化文字 / 占位符 */
  --brand: #DE8337;              /* 品牌橙：Primary Action / Active / Focus */
  --brand-hover: #CC7228;
  --brand-soft: #FFF2E4;
  --success: #2E9E6B;
  --success-soft: #E2F3EA;
  --warning: #D97F2B;
  --warning-soft: #FDF0DF;
  --danger: #CF5C4F;
  --danger-soft: #FBE7E4;
  --info: #4A7FD4;
  --info-soft: #E7EEFB;

  /* ---------- Spacing（新增 UI 优先使用；旧代码既有字面值暂不清理） ---------- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* ---------- Radius（小控件 8 / 表单 10 / Card 12 / Modal·Drawer 16） ---------- */
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* ---------- Shadow（克制；以 Border / Surface / Spacing 建立层级） ---------- */
  --shadow-sm: 0 1px 2px rgba(40, 36, 31, .04), 0 1px 3px rgba(40, 36, 31, .05);
  --shadow-md: 0 2px 4px rgba(40, 36, 31, .05), 0 6px 16px rgba(40, 36, 31, .06);
  --shadow-lg: 0 4px 8px rgba(40, 36, 31, .06), 0 14px 34px rgba(40, 36, 31, .10);

  /* ---------- Typography ---------- */
  --font-family-base: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", "system-ui", sans-serif;
  --font-size-xs: 12px;
  --font-size-sm: 13px;
  --font-size-md: 14px;
  --font-size-lg: 15px;
  --font-size-xl: 18px;
  --font-size-2xl: 24px;

  /* ---------- Legacy 别名（旧 selector 继续工作；单一事实来源） ---------- */
  --canvas: var(--bg);
  --canvas-deep: #EFEAE1;
  --panel: var(--surface);
  --panel-soft: var(--surface-subtle);
  --ink: var(--text-primary);
  --ink-soft: var(--text-secondary);
  --ink-faint: var(--text-tertiary);
  --line: var(--border);
  --accent: var(--brand);
  --accent-deep: var(--brand-hover);
  --accent-soft: var(--brand-soft);
  --green: var(--success);
  --green-soft: var(--success-soft);
  --orange: var(--warning);
  --orange-soft: var(--warning-soft);
  --red: var(--danger);
  --red-soft: var(--danger-soft);
  --blue: var(--info);
  --blue-soft: var(--info-soft);
  --gray-soft: #F0ECE4;
  --shadow: var(--shadow-md);
  --radius: var(--radius-xl);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  /* Admin Shell 使用稳定平整背景；登录页装饰背景由 .login-wrap 自行 scoped 保留 */
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-family-base);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(224, 138, 60, .16);
  background: #fff;
}

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

::selection { background: rgba(224, 138, 60, .25); }

/* 滚动条 */
* { scrollbar-width: thin; scrollbar-color: #d9cbb6 transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: #d9cbb6; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #c9b695; background-clip: content-box; border: 2px solid transparent; }
*::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }

/* ---------- 布局：Admin Shell（Phase 2） ---------- */

.shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar：Desktop（>=1200）固定 236px；<1200 进入 Drawer 模式（见 Media Queries） */
.sidebar {
  width: 236px;
  flex: 0 0 236px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--surface-subtle);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar__brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-hover));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 600;
}

.sidebar__brand-text { min-width: 0; }
.sidebar__brand-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
}
.sidebar__brand-sub { font-size: 11px; color: var(--text-tertiary); }
.sidebar__close { display: none; margin-left: auto; }

.sidebar__nav {
  flex: 1;
  min-height: 0;
  padding: 10px 10px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 导航分组 */
.nav-group { margin-bottom: 2px; }

.nav-group__head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.6px;
  color: var(--text-tertiary);
  text-align: left;
  cursor: pointer;
  transition: background .14s ease, color .14s ease;
}

.nav-group__head:hover {
  background: var(--surface);
  color: var(--text-secondary);
}

.nav-group__chevron {
  margin-left: auto;
  width: 14px;
  height: 14px;
  transition: transform .18s ease;
}

.nav-group.is-open .nav-group__chevron { transform: rotate(90deg); }

.nav-group__items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0 4px 8px;
}

.nav-group:not(.is-open) .nav-group__items { display: none; }

/* 导航项（SVG 图标 + 文案；Active 使用 brand-soft + 少量 brand accent） */
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background .14s ease, color .14s ease;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  color: var(--text-tertiary);
  transition: color .14s ease;
}

.nav-item:hover { background: var(--surface); color: var(--text-primary); }
.nav-item:hover svg { color: var(--text-secondary); }

.nav-item.active {
  background: var(--brand-soft);
  color: var(--text-primary);
  font-weight: 600;
}

.nav-item.active svg { color: var(--brand); }

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -2px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}

/* Sidebar 底部管理员区 */
.sidebar__admin {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  flex-shrink: 0;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: background .14s ease;
}

.sidebar__admin:hover { background: var(--surface-subtle); }
.sidebar__admin .avatar { width: 30px; height: 30px; font-size: 12px; }
.sidebar__admin-main { flex: 1; min-width: 0; }
.sidebar__admin-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar__admin-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__admin-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
  transition: transform .18s ease;
}

.sidebar__admin[aria-expanded="true"] .sidebar__admin-chevron {
  transform: rotate(90deg);
}

/* Drawer 遮罩（<1200 生效） */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgba(40, 36, 31, .45);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}

.sidebar-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

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

.page-content {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 32px;
  min-width: 0;
}

/* Topbar：页面上下文 + 全局操作；业务操作不属于 Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar__menu {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .14s ease, color .14s ease;
}

.topbar__menu:hover { background: var(--surface-subtle); color: var(--text-primary); }
.topbar__menu svg { width: 20px; height: 20px; }

.topbar__context { min-width: 0; }
.topbar h1 {
  font-size: 18px;
  line-height: 24px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-sub {
  color: var(--text-tertiary);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

/* Tablet / Mobile：仅头像按钮（44px touch target，32px 视觉） */
.topbar__account {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .14s ease;
}

.topbar__account:hover { background: var(--surface-subtle); }

.topbar__account-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-hover));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
}

/* Account Popover（轻量；不伪造 admin_role） */
.account-popover-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: transparent;
}

.account-popover {
  position: fixed;
  z-index: 61;
  width: 240px;
  max-width: calc(100vw - 24px);
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

/* Desktop：从 Sidebar 左下区域向右上方展开 */
.account-popover--sidebar {
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
}

/* Tablet / Mobile：挂在 Topbar Avatar 下方右对齐 */
.account-popover--topbar {
  right: 12px;
  top: calc(64px + 8px);
}

.account-popover__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}

.account-popover__info { min-width: 0; }
.account-popover__name {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-popover__meta {
  font-size: 11px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-popover__divider {
  height: 1px;
  margin: 6px 0;
  background: var(--border);
}

.account-popover__logout {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: var(--font-size-sm);
  text-align: left;
  cursor: pointer;
  transition: background .14s ease;
}

.account-popover__logout:hover { background: var(--danger-soft); }

@media (max-width: 640px) {
  .account-popover--topbar { top: calc(56px + 8px); }
}

@media (max-width: 767px) {
  .account-popover__logout { min-height: 44px; }
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-hover));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
}

/* ---------- 卡片与统计 ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
  transition: box-shadow .18s, transform .18s;
}

.card:hover { box-shadow: var(--shadow); }
.card + .card { margin-top: 18px; }

.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: .1px;
}

.card-title .hint { font-size: 12px; color: var(--ink-faint); font-weight: 400; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}

.stat {
  position: relative;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s, transform .18s;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(224, 138, 60, .45), transparent);
  opacity: .8;
}

.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat .num {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: .3px;
  line-height: 1.15;
  background: linear-gradient(135deg, var(--ink), #6a563f);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat .label { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.stat .sub { font-size: 11px; color: var(--ink-faint); margin-top: 5px; }
.stat.accent .num { background: linear-gradient(135deg, var(--accent), var(--accent-deep)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.stat.green .num { background: linear-gradient(135deg, #3bb37f, var(--green)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
}

.two-col + .two-col { margin-top: 18px; }

.two-col .card {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.grow { flex: 1; min-height: 0; }

/* ---------- 图表 ---------- */

.bars {
  display: flex;
  align-items: flex-end;
  gap: clamp(3px, .6vw, 8px);
  height: 180px;
  padding: 8px 2px 0;
}

/* 事件类型环形图：图表区与柱状图同高，图例在下方与柱状图图例对齐 */
.donut-stage {
  height: 180px;
  display: grid;
  place-items: center;
}

.donut { width: 150px; height: 150px; }
.donut svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 4px 10px rgba(70, 52, 28, .12)); }
.donut circle { transition: opacity .15s; }
.donut circle:hover { opacity: .72; }

/* 数据上传同意（紧凑版） */
.consent-compact { display: flex; flex-direction: column; justify-content: flex-start; }
.stacked-bar {
  display: flex;
  height: 14px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--gray-soft);
  box-shadow: inset 0 1px 2px rgba(70, 52, 28, .08);
}
.stacked-bar i { min-width: 0; transition: width .3s; }
.consent-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 18px;
}
.consent-stat {
  position: relative;
  text-align: center;
  background: var(--panel-soft);
  border: 1px solid #f0e7d8;
  border-radius: 12px;
  padding: 12px 8px 10px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.consent-stat:hover {
  border-color: var(--accent);
  box-shadow: 0 3px 10px rgba(224, 138, 60, .15);
  transform: translateY(-1px);
}
.consent-stat.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.consent-stat strong { display: block; font-size: 20px; font-weight: 700; line-height: 1.1; }
.consent-stat span { font-size: 12px; color: var(--ink-faint); }
.consent-caret {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 10px;
  font-style: normal;
  color: var(--ink-faint);
}
.consent-note { margin: 16px 0 0; font-size: 12px; color: var(--ink-faint); text-align: center; }

/* 同意模块：点击数字展开的用户明细 */
.consent-expand {
  margin-top: 14px;
  border-top: 1px dashed #eadfce;
  padding-top: 12px;
}
.consent-expand-head { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 8px; }
.consent-loading { font-size: 12px; color: var(--ink-faint); padding: 6px 0; }
.consent-users { display: flex; flex-direction: column; gap: 6px; max-height: 230px; overflow-y: auto; }
.consent-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border: 1px solid #f0e7d8;
  border-radius: 10px;
  background: var(--panel-soft);
}
.consent-user-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.consent-user-main strong { font-size: 13px; }
.consent-user-main small { font-size: 11px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.consent-user-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.consent-user-meta small { font-size: 11px; color: var(--ink-faint); }
.consent-more { margin: 8px 0 0; font-size: 11px; color: var(--ink-faint); }

.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar {
  width: 100%;
  max-width: 34px;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, #f6bd7d, var(--accent));
  min-height: 3px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
  transition: height .3s ease;
}
.bar-col.today .bar { background: linear-gradient(180deg, #8ed4b2, var(--green)); }
.bar-col span { font-size: 10px; color: var(--ink-faint); white-space: nowrap; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; }
.legend span { font-size: 12px; color: var(--ink-soft); display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.rows { display: flex; flex-direction: column; gap: 10px; }
.mini-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.mini-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); }
.mini-row .count { font-weight: 600; min-width: 28px; text-align: right; }
.mini-track { flex: 1; max-width: 96px; height: 6px; background: var(--gray-soft); border-radius: 3px; overflow: hidden; }
.mini-track i { display: block; height: 100%; background: linear-gradient(90deg, #f0a95c, var(--accent)); border-radius: 3px; transition: width .3s; }

/* 图表悬停数值提示 */
.chart-tip {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  max-width: 280px;
  padding: 7px 11px;
  border-radius: 8px;
  background: rgba(48, 37, 25, .94);
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(70, 52, 28, .28);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease;
}
.chart-tip.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- 表格 ---------- */

.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }

th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: .8px;
  text-transform: uppercase;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: var(--panel-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}

td { padding: 12px 14px; border-bottom: 1px solid #f1e9dc; vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: none; }

.cell-user { display: flex; align-items: center; gap: 11px; }
.cell-user .avatar.small { width: 30px; height: 30px; font-size: 12px; border-radius: 10px; }
.cell-user strong { display: block; font-weight: 600; }
.cell-user small { color: var(--ink-faint); font-size: 11px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill-green { background: var(--green-soft); color: var(--green); border-color: rgba(46, 158, 107, .18); }
.pill-orange { background: var(--orange-soft); color: var(--orange); border-color: rgba(217, 127, 43, .18); }
.pill-red { background: var(--red-soft); color: var(--red); border-color: rgba(207, 92, 79, .18); }
.pill-blue { background: var(--blue-soft); color: var(--blue); border-color: rgba(74, 127, 212, .18); }
.pill-gray { background: var(--gray-soft); color: var(--ink-faint); border-color: rgba(111, 98, 84, .12); }

/* ---------- 筛选与分页 ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar input { min-width: 180px; }

code {
  background: var(--gray-soft);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 11px;
}

.entitlement-max { width: 96px !important; min-width: 96px !important; }

.flag-rollout { width: 90px !important; min-width: 90px !important; }

.entitlement-select {
  width: 150px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.entitlement-cell { display: flex; align-items: center; gap: 8px; }

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.baby-tier {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-soft, #f5e6d2);
  color: var(--accent, #b06f2b);
  font-size: 11px;
  vertical-align: middle;
}
.toolbar .spacer { flex: 1; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  color: var(--ink-faint);
  font-size: 12px;
}

.pager .btns { display: flex; gap: 6px; }
.page-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--ink-soft);
  transition: border-color .14s, color .14s, background .14s, box-shadow .14s;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-deep); background: var(--accent-soft); box-shadow: 0 3px 8px rgba(224, 138, 60, .15); }
.page-btn:disabled { opacity: .45; cursor: default; }

.empty {
  text-align: center;
  color: var(--ink-faint);
  padding: 44px 0;
  font-size: 13px;
}

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

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 480px at 80% 0%, rgba(224, 138, 60, .14), transparent 60%),
    radial-gradient(800px 460px at 10% 100%, rgba(46, 158, 107, .10), transparent 55%),
    var(--canvas);
}

.login-card {
  width: 100%;
  max-width: 408px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 38px 36px 32px;
  animation: rise .35s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 17px;
  background: linear-gradient(135deg, #f0a95c, var(--accent-deep));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 27px;
  font-weight: 700;
  margin: 0 auto 18px;
  box-shadow: 0 10px 22px rgba(224, 138, 60, .34), inset 0 1px 0 rgba(255, 255, 255, .4);
}

.login-card h1 { text-align: center; font-size: 20px; margin: 0 0 4px; letter-spacing: .2px; }
.login-card .sub { text-align: center; color: var(--ink-faint); font-size: 12px; margin: 0 0 24px; }
.login-card label { display: block; font-size: 12px; color: var(--ink-soft); margin: 14px 0 6px; font-weight: 500; }
.login-card input { width: 100%; padding: 10px 13px; border-radius: 11px; }
.login-card .login-btn {
  width: 100%;
  margin-top: 24px;
  background: linear-gradient(135deg, #f0a95c, var(--accent-deep));
  color: #fff;
  border-radius: 12px;
  padding: 12px;
  font-weight: 600;
  box-shadow: 0 8px 18px rgba(224, 138, 60, .32), inset 0 1px 0 rgba(255, 255, 255, .28);
  transition: transform .12s, box-shadow .18s, filter .18s;
}
.login-card .login-btn:hover:not(:disabled) { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 10px 22px rgba(224, 138, 60, .38); }
.login-card .login-btn:active { transform: translateY(0) scale(.99); }
.login-card .login-btn:disabled { opacity: .55; cursor: default; }
.login-err { background: var(--red-soft); color: var(--red); border-radius: 11px; padding: 10px 13px; font-size: 12px; margin-top: 16px; }
.login-tip { margin-top: 20px; font-size: 11px; color: var(--ink-faint); line-height: 1.8; border-top: 1px dashed var(--line); padding-top: 16px; }
.login-tip code { background: var(--gray-soft); padding: 1px 5px; border-radius: 5px; font-size: 10.5px; }

/* ---------- 用户详情 ---------- */

.detail-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 4px 2px;
}

.back-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 11px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
  transition: color .14s, border-color .14s, background .14s, transform .12s;
}
.back-btn:hover { color: var(--accent-deep); border-color: var(--accent); background: var(--accent-soft); }
.back-btn:active { transform: scale(.97); }

.detail-avatar {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  background: linear-gradient(135deg, #f0a95c, var(--accent-deep));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 21px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(224, 138, 60, .3), inset 0 1px 0 rgba(255, 255, 255, .35);
}

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; }
.kv .item { background: var(--panel-soft); border: 1px solid #f0e7d8; border-radius: 12px; padding: 11px 14px; }
.kv .item .k { font-size: 11px; color: var(--ink-faint); letter-spacing: .4px; }
.kv .item .v { font-size: 13px; font-weight: 600; margin-top: 3px; word-break: break-all; }

.consent-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.consent-box .txt { font-size: 13px; color: var(--ink-soft); }
.consent-box .txt strong { color: var(--ink); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  background: #2b2118;
  color: #fff;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.loading { text-align: center; color: var(--ink-faint); padding: 44px 0; }
.loading::after {
  content: "";
  display: block;
  width: 22px;
  height: 22px;
  margin: 12px auto 0;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.json-detail {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--ink-soft);
  max-width: 460px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delete-btn {
  border: 1px solid rgba(207, 92, 79, .22);
  background: var(--red-soft);
  color: var(--red);
  border-radius: 9px;
  padding: 4px 11px;
  font-size: 12px;
  white-space: nowrap;
  transition: background .14s, color .14s, border-color .14s;
}
.delete-btn:hover { background: var(--red); color: #fff; border-color: var(--red); }

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.check-inline input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

/* ---------- 响应式 ---------- */

@media (max-width: 1200px) {
  .two-col { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .page-content { padding: 24px clamp(16px, 2.5vw, 28px) 48px; }
}

/* Tablet / Mobile：Sidebar 进入 Drawer 模式（<1200） */
@media (max-width: 1199px) {
  .shell { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(84vw, 320px);
    height: 100vh;
    height: 100dvh;
    flex: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform .25s ease;
  }

  .sidebar.is-open { transform: translateX(0); }
  .sidebar__close { display: inline-flex; }
  .sidebar-overlay.is-open { opacity: 1; visibility: visible; }
  .topbar__menu { display: inline-flex; }
  .topbar__account { display: inline-flex; }

  /* Touch Target：抽屉内导航与分组切换不小于 44px */
  .nav-item { min-height: 44px; }
  .nav-group__head { min-height: 44px; }
}

@media (max-width: 640px) {
  body { font-size: 13px; }
  .topbar { min-height: 56px; padding: 0 12px; gap: 10px; }
  .topbar-sub { display: none; }
  .topbar h1 { font-size: 16px; }
  .page-content { padding: 16px 16px 40px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px 14px 12px; }
  .stat .num { font-size: 22px; }
  .card { padding: 16px 14px; }
  .toolbar input { min-width: 0; width: 100%; }
  .toolbar { align-items: stretch; }
  .toolbar select { flex: 1; }
  .kv { grid-template-columns: 1fr; }
  .login-card { padding: 28px 22px 24px; }
  .detail-head { flex-wrap: wrap; }
}

/* ---------- 产品数据分析模块 ---------- */

.analytics-filters { padding: 14px 18px; }
.filter-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.filter-row.wrap { align-items: flex-end; }
.range-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.range-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-deep);
  font-weight: 600;
}
.filter-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-faint); }
.filter-field input,
.filter-field select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  min-width: 130px;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.metric-card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(90, 74, 54, .04);
}
.metric-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-faint);
}
.metric-info {
  border: 1px solid var(--line);
  background: var(--gray-soft);
  color: var(--ink-faint);
  border-radius: 999px;
  font-size: 11px;
  padding: 2px 8px;
  cursor: pointer;
}
.metric-info:hover { color: var(--accent-deep); border-color: var(--accent); }
.metric-value { font-size: 26px; font-weight: 700; margin: 6px 0 4px; color: var(--ink); }
.metric-change { font-size: 12px; color: var(--ink-faint); }
.metric-change.up { color: var(--green); }
.metric-change.down { color: var(--red); }
.metric-change.new { color: var(--blue); }
.metric-change.flat { color: var(--ink-faint); }
.metric-popover {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  width: min(340px, 86vw);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(60, 46, 30, .16);
  padding: 12px 14px;
  font-size: 12px;
  color: var(--ink);
}
.metric-popover.hidden { display: none; }
.popover-title { font-weight: 700; margin-bottom: 8px; font-size: 13px; }
.popover-row { margin-bottom: 6px; line-height: 1.5; }
.popover-row b { display: block; color: var(--ink-faint); font-weight: 600; margin-bottom: 2px; }

/* ---------- Phase 5B-2：产品分析信息层级 ---------- */

.analytics-section {
  margin-bottom: 24px;
}

.analytics-section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.analytics-section__title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  color: var(--ink);
}

.analytics-section__hint {
  font-size: 12px;
  color: var(--ink-faint);
}

.analytics-metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.analytics-metric-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: 0 1px 2px rgba(90, 74, 54, .04);
}

.analytics-metric-card__label {
  font-size: 13px;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.analytics-metric-card__value {
  font-size: 28px;
  font-weight: 750;
  color: var(--ink);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.analytics-metric-card__change {
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-faint);
}

.analytics-metric-card__change.up { color: var(--green); }
.analytics-metric-card__change.down { color: var(--red); }
.analytics-metric-card__change.new { color: var(--blue); }

/* Overview 指标分层：Primary 大数字，Secondary/Health 紧凑 */
.metric-card--primary .metric-value { font-size: 32px; }
.metric-card--secondary .metric-value { font-size: 22px; }
.metric-card--secondary .metric-card { border-radius: 12px; }
.analytics-metric-grid--secondary,
.analytics-metric-grid--health {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}
.analytics-metric-grid--health .metric-card {
  background: var(--gray-soft);
}

.analytics-capability {
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--gray-soft);
  padding: 14px 16px;
}

.analytics-capability__title {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
}

.analytics-capability__note {
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-faint);
}

.analytics-capability__items {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.analytics-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-faint);
}

.analytics-flow {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}

.analytics-flow__step {
  flex: 1 1 150px;
  min-width: 140px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.analytics-flow__label {
  font-size: 12px;
  color: var(--ink-faint);
}

.analytics-flow__value {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.analytics-flow__meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--ink-faint);
}

.analytics-flow__rate {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-faint);
  white-space: nowrap;
  padding-top: 12px;
}

.analytics-flow__rate-arrow { color: var(--line); }
.analytics-flow__rate--na { color: var(--ink-faint); }

.analytics-alert {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 13px;
  background: var(--gray-soft);
}

.analytics-alert--critical,
.analytics-alert--high { border-color: rgba(214, 82, 62, .35); background: var(--red-soft); color: var(--red); }
.analytics-alert--warning { border-color: rgba(217, 127, 43, .3); background: var(--orange-soft); }
.analytics-alert--info { border-color: rgba(74, 127, 212, .3); background: var(--blue-soft); color: var(--blue); }

.trend-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trend-toggle {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-faint);
  border-radius: 999px;
  font-size: 12px;
  padding: 4px 11px;
  cursor: pointer;
}

.trend-toggle.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-deep);
  font-weight: 600;
}

.analytics-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

/* Retention：Cohort 热度矩阵（品牌色深浅 + 数值文本，颜色不是唯一表达） */
.cohort-cell {
  background: rgba(224, 138, 60, calc(var(--heat, 0) / 100 * 0.22));
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.cohort-table td,
.cohort-table th {
  white-space: nowrap;
}

/* Analytics Toolbar：时间范围组 与 页面筛选组 视觉分离 */
.analytics-toolbar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.analytics-toolbar__group {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.analytics-toolbar__divider {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  min-height: 30px;
}

.analytics-note {
  margin: 2px 0 20px;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--ink-soft);
  font-size: 12px;
  border-radius: 0 10px 10px 0;
}

/* ---------- Phase 6：工具模块收口 ---------- */

.test-account-note {
  margin-bottom: 18px;
  padding: 10px 14px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--gray-soft);
  color: var(--ink-soft);
  font-size: 12px;
}

.test-account-created {
  border-color: var(--accent);
}

.audit-detail-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-family-mono);
  font-size: 12px;
  color: var(--ink-faint);
}

.audit-table .ui-badge,
.test-accounts-table .ui-badge {
  white-space: nowrap;
}

.event-health-table td {
  white-space: nowrap;
}

.analytics-raw-filters .filter-field input {
  min-width: 140px;
}

@media (max-width: 640px) {
  .audit-detail-cell { max-width: 160px; }
  .test-accounts-table .action-cell { white-space: nowrap; }
}
.analytics-banner {
  border-radius: 12px;
  padding: 10px 14px;
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.55;
}
.analytics-banner.amber { background: var(--orange-soft); color: var(--orange); border: 1px solid rgba(217, 127, 43, .22); }
.analytics-banner.gray { background: var(--gray-soft); color: var(--ink-faint); border: 1px solid var(--line); }
.analytics-banner.blue { background: var(--blue-soft); color: var(--blue); border: 1px solid rgba(74, 127, 212, .22); }
.analytics-updated { font-size: 12px; color: var(--ink-faint); margin: 0 0 14px; }
.chart-block { margin-top: 8px; }
.chart-legend-wrap { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; font-size: 12px; color: var(--ink-faint); }
.chart-legend { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.line-chart { width: 100%; height: auto; }
.bar-row {
  display: grid;
  grid-template-columns: 150px 1fr 72px;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
}
.bar-label { color: var(--ink); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--gray-soft); border-radius: 999px; height: 18px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 999px; transition: width .3s ease; }
.bar-value { color: var(--ink-faint); }
.funnel-row { display: grid; grid-template-columns: 1fr 84px; align-items: center; gap: 10px; margin-bottom: 8px; }
.funnel-bar {
  background: linear-gradient(90deg, var(--accent-soft), var(--accent));
  color: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  min-width: 60px;
}
.funnel-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.funnel-value { font-weight: 700; white-space: nowrap; }
.funnel-rate { text-align: center; font-size: 13px; color: var(--ink-faint); }
.alert-item { border-radius: 10px; padding: 9px 12px; margin-bottom: 8px; font-size: 13px; background: var(--gray-soft); }
.alert-item.warning { background: var(--orange-soft); color: var(--orange); }
.alert-item.error { background: var(--red-soft); color: var(--red); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.mini-stat {
  background: var(--gray-soft);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mini-stat span { font-size: 12px; color: var(--ink-faint); }
.mini-stat b { font-size: 20px; }
.mini-stat small { font-size: 11px; color: var(--ink-faint); }
.big-number { font-size: 40px; font-weight: 800; color: var(--accent-deep); display: flex; align-items: baseline; gap: 8px; }
.big-number small { font-size: 13px; color: var(--ink-faint); font-weight: 400; }
.segment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.segment-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--gray-soft);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--ink-faint);
}
.segment-chip b { color: var(--ink); font-size: 14px; }
.muted { color: var(--ink-faint); font-size: 12px; margin-top: 8px; }
.table-scroll { overflow-x: auto; }
.core-row { background: rgba(74, 127, 212, .04); }
.param-summary { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-faint); font-size: 12px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 14px; font-size: 13px; color: var(--ink-faint); }
.recalc-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(45, 35, 25, .42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 18px;
  width: min(720px, 94vw);
  max-height: 86vh;
  overflow: auto;
  box-shadow: 0 24px 64px rgba(45, 35, 25, .28);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-close { border: none; background: none; font-size: 22px; color: var(--ink-faint); cursor: pointer; }
.modal-body { padding: 16px 20px 20px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 14px; margin-bottom: 14px; }
.detail-grid > div { font-size: 13px; }
.detail-grid span { display: block; font-size: 11px; color: var(--ink-faint); }
.json-block {
  background: #2d261f;
  color: #f3eadb;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12px;
  overflow-x: auto;
  max-height: 340px;
  white-space: pre-wrap;
  word-break: break-all;
}
@media (max-width: 640px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 96px 1fr 56px; }
  .funnel-row { grid-template-columns: 1fr 64px; }
  .analytics-metric-grid { grid-template-columns: repeat(2, 1fr); }
  .analytics-metric-card__value { font-size: 22px; }
  .analytics-toolbar__divider { display: none; }
  .analytics-flow { flex-direction: column; align-items: stretch; }
  .analytics-flow__step { padding: 12px 14px; min-height: 0; }
  .analytics-flow__label { font-size: 12px; }
  .analytics-flow__value { font-size: 22px; font-weight: 650; margin-top: 2px; }
  .analytics-flow__meta { margin-top: 2px; }
  .analytics-flow__rate {
    height: 28px;
    padding: 0 8px;
    justify-content: center;
    font-size: 12px;
  }
}

/* ---------- 诊断中心（v2：管理工作流重排） ---------- */

.diag-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.diag-stats { font-size: 13px; color: var(--ink-soft); }
.diag-actions { display: flex; gap: 8px; align-items: center; }

.diag-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.diag-search-input {
  flex: 0 1 520px;
  min-width: 260px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
}
.diag-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(224, 138, 60, .14);
}
.diag-search-btn { height: 38px; }

.diag-common-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}
.diag-compact-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
}
.diag-compact-filter select {
  height: 34px;
  min-width: 132px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
}

.diag-advanced {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-soft);
  margin-bottom: 12px;
}
.diag-advanced.hidden { display: none; }
.diag-advanced label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--ink-faint);
}
.diag-advanced select,
.diag-advanced input {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
}

.diag-table-wrap { overflow-x: auto; }
.diag-table { width: 100%; border-collapse: collapse; }
.diag-table th {
  text-align: left;
  font-size: 11px;
  color: var(--ink-faint);
  font-weight: 600;
  letter-spacing: .4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.diag-table td {
  padding: 13px 12px;
  border-bottom: 1px solid #f3ead9;
  font-size: 12px;
  color: var(--ink);
  vertical-align: middle;
}
.diag-table tbody tr { cursor: pointer; }
.diag-table tbody tr:hover td { background: var(--panel-soft); }
.diag-table tbody tr:last-child td { border-bottom: none; }
.diag-number {
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--ink);
}
.diag-desc { display: inline-block; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.diag-row-actions { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.diag-export-btn { white-space: nowrap; }

.diag-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.diag-detail-title {
  font-size: 20px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.diag-detail-sub { font-size: 12px; color: var(--ink-faint); margin: 4px 0 8px; }
.diag-detail-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.diag-detail-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.diag-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s, border-color .14s;
}
.diag-primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.diag-section { margin-top: 16px; }
.diag-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 10px;
}
.diag-timeline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.diag-timeline-head select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
}
.diag-raw-details summary {
  cursor: pointer;
  user-select: none;
}
.diag-raw-details summary:hover { color: var(--accent-deep); }

.diag-timeline { display: flex; flex-direction: column; gap: 0; }
.diag-tl-item {
  display: grid;
  grid-template-columns: 128px 52px 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px dashed #f0e7d8;
  font-size: 12px;
}
.diag-tl-item:last-child { border-bottom: none; }
.diag-tl-time { font-size: 11px; color: var(--ink-faint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.diag-tl-kind { justify-self: start; }
.diag-tl-text { color: var(--ink-soft); word-break: break-all; }
.diag-tl-error .diag-tl-text { color: var(--red); }

.diag-raw-pre {
  background: #2d261f;
  color: #f3eadb;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 11px;
  line-height: 1.55;
  overflow: auto;
  max-height: 360px;
  white-space: pre-wrap;
  word-break: break-all;
}

.row-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.desc-block { margin-top: 10px; }
.desc-block p { font-size: 13px; color: var(--ink-soft); margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.form-row select,
.form-row input {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
}
.form-row select { min-width: 150px; }
.form-row input { min-width: 180px; }
textarea#diag-notes {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
  resize: vertical;
}

@media (max-width: 900px) {
  .diag-search-input { flex: 1 1 100%; }
  .diag-tl-item { grid-template-columns: 110px 1fr; }
  .diag-tl-kind { display: none; }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS（统一断点管理区）
   --------------------------------------------------------------------------
   Large Desktop               : >= 1440px
   Desktop                     : 1200px ~ 1439px
   Tablet Landscape / Small Desktop : 992px ~ 1199px
   Tablet Portrait             : 768px ~ 991px
   Mobile                      : < 768px
   Small Mobile                : < 480px

   说明：旧断点 1200 / 980 / 900 / 640 仍在使用，本轮不删除；
   所有新增响应式代码一律向本表收敛。
   ========================================================================== */

/* ==========================================================================
   DESIGN SYSTEM（Phase 1 公共基础设施）
   --------------------------------------------------------------------------
   原则：先新增 → 后迁移 → 最后清理。
   本阶段只建立统一能力，不改动 21 个页面模板；
   旧 selector 全部保留，新 .ui-* 体系独立存在。
   ========================================================================== */

/* ---------- 2. Base & Accessibility ---------- */

button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  /* 聚焦反馈由各控件的 :focus border + ring 提供，避免双重描边 */
}

/* 动效降级：尊重 prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- 3. Layout System ---------- */

.ui-container {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--space-8);
}

.ui-grid {
  display: grid;
  gap: var(--space-4);
}

/* KPI / Metric：Desktop 4 列；Tablet 2 列；Mobile 2 列 → Small Mobile 1 列（见 Media Queries） */
.ui-grid--metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* 信息复杂的指标区使用单列，避免窄卡 */
.ui-grid--metrics.ui-grid--single {
  grid-template-columns: 1fr;
}

.ui-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.ui-stack--sm {
  gap: var(--space-2);
}

.ui-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.ui-responsive-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* ---------- 4. Responsive Utilities ---------- */

.ui-mobile-only,
.ui-tablet-only,
.ui-desktop-only {
  display: none;
}

@media (min-width: 1200px) {
  .ui-desktop-only { display: revert; }
}

@media (min-width: 768px) and (max-width: 1199px) {
  .ui-tablet-only { display: revert; }
}

@media (max-width: 767px) {
  .ui-mobile-only { display: revert; }
}

/* Mobile 导航预留（Phase 2 实现行为；本阶段只建立 CSS 基础） */
.ui-mobile-nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(40, 36, 31, .45);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
}

.ui-mobile-nav-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.ui-mobile-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1501;
  display: flex;
  flex-direction: column;
  width: min(84vw, 320px);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow-y: auto;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(-100%);
  transition: transform .25s ease;
}

.ui-mobile-sidebar.is-open {
  transform: translateX(0);
}

/* ---------- 5. Typography ---------- */

.ui-title-page {
  font-size: var(--font-size-2xl);
  line-height: 32px;
  font-weight: 600;
  color: var(--text-primary);
}

.ui-title-section {
  font-size: var(--font-size-xl);
  line-height: 26px;
  font-weight: 600;
  color: var(--text-primary);
}

.ui-title-card {
  font-size: var(--font-size-lg);
  line-height: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.ui-text-body {
  font-size: var(--font-size-md);
  line-height: 22px;
  font-weight: 400;
  color: var(--text-primary);
}

.ui-text-secondary {
  font-size: var(--font-size-sm);
  line-height: 20px;
  font-weight: 400;
  color: var(--text-secondary);
}

.ui-text-tertiary {
  font-size: var(--font-size-xs);
  line-height: 18px;
  font-weight: 400;
  color: var(--text-tertiary);
}

.ui-kpi-value {
  font-size: 30px;
  line-height: 36px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ---------- 6. Button ---------- */

.ui-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 500;
  line-height: 1;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease,
    color .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.ui-button:hover {
  background: var(--surface-subtle);
}

.ui-button:active {
  box-shadow: inset 0 1px 2px rgba(40, 36, 31, .08);
}

.ui-button:disabled,
.ui-button.is-disabled {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

.ui-button--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #FFFFFF;
}

.ui-button--primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.ui-button--primary:active {
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .18);
}

.ui-button--secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.ui-button--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.ui-button--ghost:hover {
  background: var(--surface-subtle);
  color: var(--text-primary);
}

.ui-button--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #FFFFFF;
}

.ui-button--danger:hover {
  box-shadow: inset 0 0 0 999px rgba(0, 0, 0, .08);
}

.ui-button--danger:active {
  box-shadow: inset 0 0 0 999px rgba(0, 0, 0, .14);
}

/* Loading 态：文字隐藏 + 圆环（色值按按钮变体覆盖） */
.ui-button.is-loading {
  color: transparent !important;
  pointer-events: none;
}

.ui-button.is-loading::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: ui-spin .7s linear infinite;
}

.ui-button--primary.is-loading::after,
.ui-button--danger.is-loading::after {
  border-color: rgba(255, 255, 255, .35);
  border-top-color: #FFFFFF;
}

.ui-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
}

.ui-icon-button:hover {
  background: var(--surface-subtle);
  color: var(--text-primary);
}

/* ---------- 7. Form Controls ---------- */

.ui-form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.ui-input,
.ui-select,
.ui-search {
  width: 100%;
  min-height: 36px;
  padding: 0 12px;
  font-family: inherit;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.ui-input:hover,
.ui-select:hover,
.ui-search:hover {
  border-color: var(--border-strong);
}

.ui-input:focus,
.ui-select:focus,
.ui-search:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(222, 131, 55, .18);
}

.ui-input::placeholder,
.ui-search::placeholder {
  color: var(--text-tertiary);
}

.ui-input:disabled,
.ui-select:disabled,
.ui-search:disabled {
  background: var(--surface-subtle);
  color: var(--text-tertiary);
  cursor: not-allowed;
  opacity: .8;
}

.ui-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%2370685F' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.ui-search {
  min-width: 220px;
}

/* ---------- 8. Card ---------- */

.ui-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.ui-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) 0;
}

.ui-card__body {
  padding: var(--space-4);
}

.ui-card__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: 0 var(--space-4) var(--space-4);
}

/* ---------- 9. Badge ---------- */

.ui-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding: 0 8px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 999px;
  white-space: nowrap;
}

.ui-badge--neutral {
  background: var(--surface-subtle);
  color: var(--text-secondary);
  border-color: var(--border);
}

.ui-badge--success {
  background: var(--success-soft);
  color: var(--success);
}

.ui-badge--warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.ui-badge--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.ui-badge--info {
  background: var(--info-soft);
  color: var(--info);
}

/* ---------- 10. Table ---------- */

.ui-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.ui-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

/* 简单列表可关闭默认 min-width，避免小表强制横向滚动 */
.ui-table--fluid {
  min-width: 0;
}

.ui-table th {
  padding: 10px 12px;
  font-size: var(--font-size-xs);
  font-weight: 500;
  line-height: 18px;
  color: var(--text-tertiary);
  text-align: left;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.ui-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  vertical-align: middle;
}

.ui-table tbody tr:last-child td {
  border-bottom: none;
}

.ui-table tbody tr:hover {
  background: var(--surface-subtle);
}

.ui-table td.ui-table__empty {
  padding: var(--space-8) var(--space-4);
  color: var(--text-tertiary);
  text-align: center;
}

/* ---------- 11. Page Header ---------- */

.ui-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding-bottom: var(--space-6);
}

.ui-page-header__content {
  min-width: 0;
}

.ui-page-header__title {
  margin: 0;
  font-size: var(--font-size-2xl);
  line-height: 32px;
  font-weight: 600;
  color: var(--text-primary);
}

.ui-page-header__subtitle {
  margin: 4px 0 0;
  font-size: var(--font-size-sm);
  line-height: 20px;
  color: var(--text-secondary);
}

.ui-page-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ---------- 12. Filter ---------- */

.ui-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.ui-filter-bar .ui-input,
.ui-filter-bar .ui-select,
.ui-filter-bar .ui-search {
  flex: 0 1 200px;
}

.ui-filter-bar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

/* ---------- 13. Metric ---------- */

.ui-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.ui-metric__label {
  font-size: var(--font-size-sm);
  line-height: 20px;
  color: var(--text-secondary);
}

.ui-metric__value {
  font-size: 30px;
  line-height: 36px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.ui-metric__meta {
  font-size: var(--font-size-xs);
  line-height: 18px;
  color: var(--text-tertiary);
}

/* ---------- 14. Feedback States ---------- */

.ui-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--font-size-sm);
  text-align: center;
}

.ui-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  color: var(--text-tertiary);
  font-size: var(--font-size-sm);
}

.ui-loading::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: ui-spin .8s linear infinite;
}

.ui-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4);
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(207, 92, 79, .25);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-sm);
  text-align: center;
}

@keyframes ui-spin {
  to { transform: rotate(360deg); }
}

/* ---------- 15. Toast ---------- */

.ui-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 2000;
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  background: var(--text-primary);
  color: #FFFFFF;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: 20px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity .2s ease, transform .2s ease, visibility .2s ease;
}

.ui-toast.is-visible {
  opacity: 1;
  visibility: visible;
}

/* ---------- 16. Dialog ---------- */

.ui-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(40, 36, 31, .45);
}

.ui-dialog {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(85vh, 720px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.ui-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
}

.ui-dialog__title {
  margin: 0;
  font-size: var(--font-size-lg);
  line-height: 22px;
  font-weight: 600;
}

.ui-dialog__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-tertiary);
  font-size: 16px;
  cursor: pointer;
}

.ui-dialog__close:hover {
  background: var(--surface-subtle);
  color: var(--text-primary);
}

.ui-dialog__body {
  padding: var(--space-4) var(--space-6);
  overflow-y: auto;
}

.ui-dialog__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
}

/* ---------- 17. Drawer ---------- */

.ui-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(40, 36, 31, .45);
}

.ui-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1501;
  display: flex;
  flex-direction: column;
  width: min(560px, 100vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform .25s ease;
}

.ui-drawer.is-open {
  transform: translateX(0);
}

.ui-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border);
}

.ui-drawer__title {
  margin: 0;
  font-size: var(--font-size-lg);
  line-height: 22px;
  font-weight: 600;
}

.ui-drawer__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-tertiary);
  font-size: 16px;
  cursor: pointer;
}

.ui-drawer__close:hover {
  background: var(--surface-subtle);
  color: var(--text-primary);
}

.ui-drawer__body {
  flex: 1;
  padding: var(--space-4) var(--space-6);
  overflow-y: auto;
}

.ui-drawer__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
}

/* ---------- 18. Responsive Media Queries（新增体系向统一断点收敛） ---------- */

/* Tablet Landscape / Small Desktop（992 ~ 1199） */
@media (min-width: 992px) and (max-width: 1199px) {
  .ui-container {
    padding: var(--space-6);
  }
  .ui-grid--metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Tablet Portrait（768 ~ 991） */
@media (min-width: 768px) and (max-width: 991px) {
  .ui-container {
    padding: var(--space-6);
  }
  .ui-grid--metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .ui-drawer {
    width: 70vw;
  }
}

/* Mobile（< 768） */
@media (max-width: 767px) {
  .ui-container {
    padding: var(--space-4);
  }

  .ui-page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .ui-page-header__actions {
    width: 100%;
  }

  .ui-filter-bar .ui-input,
  .ui-filter-bar .ui-select,
  .ui-filter-bar .ui-search {
    flex: 1 1 100%;
    min-width: 0;
  }

  .ui-filter-bar__actions {
    margin-left: 0;
    width: 100%;
  }

  .ui-filter-bar__actions .ui-button {
    flex: 1;
  }

  .ui-grid--metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ui-dialog {
    width: calc(100vw - 32px);
  }

  .ui-drawer {
    width: 100vw;
    padding-top: env(safe-area-inset-top);
  }

  /* Touch Target：重要交互不小于 44px */
  .ui-button {
    min-height: 44px;
  }

  .ui-icon-button,
  .ui-dialog__close,
  .ui-drawer__close {
    width: 44px;
    height: 44px;
  }
}

/* Small Mobile（< 480） */
@media (max-width: 479px) {
  .ui-container {
    padding: var(--space-3);
  }

  .ui-grid--metrics {
    grid-template-columns: 1fr;
  }
}

/* Touch 设备：不保留粘滞 hover 背景，重要操作不依赖 hover 才能发现 */
@media (hover: none) and (pointer: coarse) {
  .ui-button:hover,
  .ui-button--secondary:hover {
    background: var(--surface);
  }

  .ui-button--primary:hover {
    background: var(--brand);
  }

  .ui-button--ghost:hover {
    background: transparent;
  }

  .ui-button--danger:hover {
    box-shadow: none;
  }

  .ui-table tbody tr:hover {
    background: transparent;
  }

  .ui-icon-button:hover,
  .ui-dialog__close:hover,
  .ui-drawer__close:hover {
    background: none;
  }
}

/* ==========================================================================
   LEGACY COMPATIBILITY（旧系统继续工作）
   --------------------------------------------------------------------------
   以下旧 selector 全部保留、未删除：
   shell / sidebar / brand / nav-* / main / topbar / avatar /
   card / stat / consent-* / bars / donut-* / chart-* / legend / rows / mini-* /
   table-wrap / table / th / td / pill / pill-* / toolbar / entitlement-* /
   flag-* / inline-check / baby-tier / pager / page-btn / btn / empty / loading /
   login-* / detail-* / back-btn / kv / toast / modal-* / json-detail / delete-btn /
   check-inline / analytics-* / filter-row / range-btn / filter-field / metric-* /
   popover-* / data-table / bar-* / funnel-* / segment-* / big-number / mini-stat /
   recalc-row / alert-item / core-row / param-summary / json-block / detail-grid /
   modal-backdrop / table-scroll / diag-* / form-row / textarea#diag-notes …

   说明：Phase 3 账户入口去重时删除了 Topbar 专用 selector
   .user-chip / .logout-btn（账户入口统一收敛到 Sidebar 账户行 + 唯一 Account Popover）。

   新 .ui-* 体系独立存在；Phase 3 ~ Phase 10 逐页迁移后再统一清理旧 selector。
   ========================================================================== */

/* ==========================================================================
   PHASE 3 页面迁移（overview / users 样板页 scoped 规则）
   --------------------------------------------------------------------------
   只新增两个页面真正需要的少量规则；其余一律复用 Phase 1 .ui-* 体系。
   ========================================================================== */

/* ---------- Topbar / PageHeader 职责划分 ---------- */
/* 已迁移页面：Desktop Topbar 只保留轻量区域 Context；标题进入 .ui-page-header */
.topbar__context--migrated .topbar__context-label {
  display: block;
  font-size: 13px;
  line-height: 20px;
  color: var(--text-tertiary);
}

.topbar__context--migrated .topbar__title {
  display: none;
}

@media (max-width: 1199px) {
  /* Tablet / Mobile：Topbar 显示短页面标题，不显示长 subtitle */
  .topbar__context--migrated .topbar__context-label {
    display: none;
  }
  .topbar__context--migrated .topbar__title {
    display: block;
    font-size: 16px;
    line-height: 24px;
  }
}

/* ---------- Overview：KPI ---------- */
/* 数字最强、名称次之、meta 最弱；大部分白色 surface，状态色只用于数字 */
.overview-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (min-width: 1440px) {
  .overview-metrics { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (min-width: 992px) and (max-width: 1439px) {
  .overview-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 768px) and (max-width: 991px) {
  .overview-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* 390px 短 KPI 卡仍允许 2 列（覆盖 Phase 1 的 <480 单列规则） */
@media (max-width: 767px) {
  .overview-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.ui-metric--success .ui-metric__value {
  color: var(--success);
}

/* ---------- Overview：图表区 ---------- */
/* >=992 双列；<992 单列（修复 820px 双图过窄） */
.overview-charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-4);
}

@media (max-width: 991px) {
  .overview-charts { grid-template-columns: 1fr; }
}

/* ---------- Overview：14 天 X 轴标签密度 ---------- */
/* 数据点全部保留；仅按视口隐藏部分文字标签 */
.bar-label {
  display: block;
}

@media (max-width: 991px) {
  .bar-label.show-tablet { display: block; }
  .bar-label:not(.show-tablet) { display: none; }
}

@media (max-width: 767px) {
  .bar-label.show-mobile { display: block; }
  .bar-label:not(.show-mobile) { display: none; }
}

/* ---------- Overview：Donut / Legend ---------- */
.donut-stage { place-items: center; }

@media (max-width: 767px) {
  .overview-charts .donut {
    width: 120px;
    height: 120px;
  }
}

@media (max-width: 639px) {
  .overview-charts .legend {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 12px;
  }
}

/* ---------- Users：列表头 / 表格 ---------- */
.ui-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) 0 var(--space-3);
}

.ui-table tbody tr {
  min-height: 48px;
}

.ui-table td {
  padding: 12px;
}

@media (hover: none) and (pointer: coarse) {
  .ui-table tbody tr:hover {
    background: transparent;
  }
}

/* ---------- Data Freshness（统一组件） ---------- */
/* 回答“这批数据统计到什么时候”；正常文档流，不与 Filter / Banner / Card 重叠 */
.ui-data-meta {
  margin: 0 0 var(--space-3);
  font-size: 12px;
  line-height: 18px;
  color: var(--text-tertiary);
}

/* ==========================================================================
   PHASE 4 页面迁移（families / events / ai / authlogs / entitlements scoped）
   --------------------------------------------------------------------------
   只新增详情页区块与表单行布局等少量 scoped 规则，其余全部复用 .ui-* 体系。
   ========================================================================== */

.page-section {
  margin-top: var(--space-6);
}

.ui-section-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-bottom: var(--space-3);
}

.ui-section-head .ui-title-section {
  margin: 0;
}

.ui-section-head .ui-button {
  margin-left: auto;
}

.ui-form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.ui-form-inline .ui-input {
  flex: 0 1 220px;
}

@media (max-width: 767px) {
  .ui-form-inline .ui-input {
    flex: 1 1 100%;
  }
  .ui-section-head .ui-button {
    margin-left: 0;
  }
}

/* ==========================================================================
   PHASE 4.1 视觉验收修正（scoped）
   --------------------------------------------------------------------------
   移动端复杂表格：保持桌面可读列宽 + 容器横向滚动，不压缩列。
   ========================================================================== */
.events-table { min-width: 900px; }
/* 时间 / 宝宝 / 类型 / 来源 / 记录人 / 删除：单行不折行 */
.events-table :is(th, td):is(:nth-child(1), :nth-child(2), :nth-child(3), :nth-child(4), :nth-child(6), :nth-child(7)) { white-space: nowrap; }
/* 内容列：合理宽度 + 继续 truncate（json-detail 已有 ellipsis） */
.events-table :is(th, td):nth-child(5) { min-width: 220px; max-width: 300px; }
.events-table .ui-badge { white-space: nowrap; }
.families-table { min-width: 760px; }
.families-table th, .families-table td { white-space: nowrap; }
/* 家庭名称（主文本）+ ID（次级、下一行）视觉分离 */
.families-table .cell-name strong { display: block; }
.families-table .cell-name small { display: block; margin-top: 2px; color: var(--text-tertiary); font-size: 11px; }

/* ==========================================================================
   PHASE 5B-1 数据状态（克制中性；未接入不是错误，不用红色刷屏）
   ========================================================================== */
.analytics-status { font-variant-numeric: tabular-nums; }
.analytics-status.status-no_data,
.analytics-status.status-not_integrated,
.analytics-status.status-unknown { color: var(--text-tertiary); }
.analytics-status.status-not_computed { color: var(--text-secondary); }
.analytics-status.status-error { color: var(--danger); }
