/* ==========================================================================
   UGC 数据中枢 v2 · UI Primitives
   只消费语义变量；每个组件一个区块，命名 .{组件}-{部件} / .is-{状态}
   ========================================================================== */

/* ---------- Button ---------- */
.btn {
  --btn-h: 32px;
  --btn-px: 12px;
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border);
  --btn-bg-hover: var(--surface-hover);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1-5);
  height: var(--btn-h);
  padding: 0 var(--btn-px);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  box-shadow: var(--shadow-xs);
  transition: background-color var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}
.btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.5; }
.btn svg { flex: 0 0 auto; }

.btn--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-fg);
  --btn-border: transparent;
  --btn-bg-hover: var(--accent-hover);
}
.btn--ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-fg: var(--text-secondary);
  --btn-bg-hover: var(--surface-active);
  box-shadow: none;
}
.btn--ghost:hover:not(:disabled) { color: var(--text); }
.btn--subtle {
  --btn-bg: var(--bg-subtle);
  --btn-border: transparent;
  --btn-bg-hover: var(--surface-active);
  box-shadow: none;
}
.btn--danger {
  --btn-bg: var(--danger);
  --btn-fg: #fff;
  --btn-border: transparent;
  --btn-bg-hover: var(--red-600);
}
.btn--sm { --btn-h: 28px; --btn-px: 10px; font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn--lg { --btn-h: 38px; --btn-px: 16px; font-size: var(--text-md); }
.btn--icon { --btn-px: 0; width: var(--btn-h); }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--btn-fg);
  border-right-color: transparent;
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
}
.btn .kbd { margin-left: var(--space-1); }

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

/* ---------- Input / Select ---------- */
.input,
.select {
  height: 32px;
  width: 100%;
  padding: 0 var(--space-2-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.input::placeholder { color: var(--text-subtle); }
.input:hover,
.select:hover { border-color: var(--border-strong); }
.input:focus-visible,
.select:focus-visible { border-color: var(--accent); box-shadow: var(--focus-ring); border-radius: var(--radius-md); }
.select { appearance: none; padding-right: 28px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ba3b1' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; }

.input-group { position: relative; display: flex; align-items: center; min-width: 0; }
.input-group > svg { position: absolute; left: 10px; color: var(--text-subtle); pointer-events: none; }
.input-group > .input { padding-left: 32px; }
.input-group > .kbd { position: absolute; right: 8px; pointer-events: none; }

/* ---------- Kbd ---------- */
.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  background: var(--surface);
  color: var(--text-muted);
  font: 500 10.5px/1 var(--font-mono);
}

/* ---------- Badge ---------- */
.badge {
  --badge-bg: var(--bg-subtle);
  --badge-fg: var(--text-secondary);
  --badge-border: transparent;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border: 1px solid var(--badge-border);
  border-radius: var(--radius-full);
  background: var(--badge-bg);
  color: var(--badge-fg);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  line-height: 1;
  white-space: nowrap;
}
.badge--square { border-radius: var(--radius-xs); }
.badge--accent { --badge-bg: var(--accent-soft); --badge-fg: var(--accent-soft-fg); }
.badge--success { --badge-bg: var(--success-soft); --badge-fg: var(--success-fg); }
.badge--warning { --badge-bg: var(--warning-soft); --badge-fg: var(--warning-fg); }
.badge--danger { --badge-bg: var(--danger-soft); --badge-fg: var(--danger-fg); }
.badge--info { --badge-bg: var(--info-soft); --badge-fg: var(--info-fg); }
.badge--outline { --badge-bg: transparent; --badge-border: var(--border); }
.badge--platform {
  --badge-bg: color-mix(in srgb, var(--pc) 12%, transparent);
  --badge-fg: var(--pc);
}
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Status Dot ---------- */
.status-dot {
  --dot: var(--text-subtle);
  position: relative;
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--dot) 16%, transparent);
}
.status-dot--ok { --dot: var(--success); }
.status-dot--running { --dot: var(--info); }
.status-dot--warning { --dot: var(--warning); }
.status-dot--danger { --dot: var(--danger); }
.status-dot.is-pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--dot);
  animation: ui-ping 1.6s var(--ease-out) infinite;
}
@keyframes ui-ping { 75%, 100% { transform: scale(2.4); opacity: 0; } }

/* ---------- Platform Mark（平台官方图标） ---------- */
.pmark {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
}
.pmark--lg { width: 28px; height: 28px; }
.pmark__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
/* 自带底色的方图：裁圆角 + 一道极细描边（原神这类浅色图在浅色底上会糊边） */
.pmark--square .pmark__img {
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(16, 24, 40, 0.10);
}
.pmark--lg.pmark--square .pmark__img { border-radius: 6px; }
/* 白色矢量标识（KK、Dota 2）：亮色主题反色成深色，暗色主题保持白色 */
[data-theme="light"] .pmark--ink .pmark__img { filter: invert(1); }
/* 徽章里的小图标：跟着文字大小走 */
.badge--platform .pmark { width: 13px; height: 13px; }
.badge--platform .pmark--square .pmark__img { border-radius: 3px; }

/* ---------- Card ---------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--duration-base) var(--ease-out), box-shadow var(--duration-base) var(--ease-out);
}
.card--interactive { cursor: pointer; }
.card--interactive:hover { border-color: var(--border-strong); box-shadow: var(--shadow-card-hover); }
.card__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 48px;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.card__header--flush { border-bottom: 0; padding-bottom: 0; }
.card__title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text); }
.card__desc { font-size: var(--text-xs); color: var(--text-muted); margin-top: 1px; }
.card__actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-1-5); }
.card__body { padding: var(--space-4); min-width: 0; flex: 1 1 auto; }
.card__body--flush { padding: 0; }
.card__footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2-5) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

/* ---------- KPI Card ---------- */
.kpi {
  --pc: var(--accent);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--pc);
  opacity: 0.85;
}
.kpi__head { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.kpi__label { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-secondary); }
.kpi__value-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3); min-width: 0; }
.kpi__value-row .spark { flex: 0 1 auto; min-width: 0; }
.kpi__value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tighter);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}
.kpi__unit { margin-left: 2px; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-muted); }
.kpi__meta { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); min-width: 0; }

/* ---------- Delta（涨跌徽标） ---------- */
.delta {
  --d-fg: var(--trend-flat);
  --d-bg: var(--trend-flat-soft);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 20px;
  padding: 0 6px 0 4px;
  border-radius: var(--radius-xs);
  background: var(--d-bg);
  color: var(--d-fg);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.delta--up { --d-fg: var(--trend-up-fg); --d-bg: var(--trend-up-soft); }
.delta--down { --d-fg: var(--trend-down-fg); --d-bg: var(--trend-down-soft); }
.delta--plain { background: transparent; padding: 0; height: auto; }

/* ---------- Sparkline ---------- */
.spark { position: relative; display: inline-block; line-height: 0; color: var(--spark, var(--accent)); }
.spark svg { overflow: visible; }
.spark__line { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark__area { fill: currentColor; opacity: 0.1; }
.spark__dot { fill: currentColor; stroke: var(--surface); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark__cursor { stroke: var(--border-strong); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark--up { --spark: var(--trend-up); }
.spark--down { --spark: var(--trend-down); }
.spark--flat { --spark: var(--text-subtle); }
.spark__tip {
  position: absolute;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  background: var(--chart-tooltip-bg);
  color: var(--chart-tooltip-fg);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
  z-index: var(--z-popover);
  font-variant-numeric: tabular-nums;
}

/* ---------- Skeleton ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  display: block;
  border-radius: var(--radius-sm);
  background: var(--skeleton-base);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
  animation: ui-shimmer 1.4s ease-in-out infinite;
}
@keyframes ui-shimmer { to { transform: translateX(100%); } }

/* ---------- Empty State ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 220px;
  padding: var(--space-8) var(--space-6);
  text-align: center;
}
.empty--compact { min-height: 140px; padding: var(--space-5); }
.empty__art { width: 120px; height: 84px; margin-bottom: var(--space-2); color: var(--text-subtle); }
.empty__title { font-size: var(--text-md); font-weight: var(--weight-semibold); color: var(--text); }
.empty__desc { max-width: 360px; font-size: var(--text-xs); color: var(--text-muted); line-height: var(--leading-normal); }
.empty__actions { display: flex; gap: var(--space-2); margin-top: var(--space-2); }

/* ---------- Toast ---------- */
.toast-region {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  --t-accent: var(--info);
  pointer-events: auto;
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: var(--space-2-5);
  align-items: start;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--duration-slow) var(--ease-out);
}
.toast.is-leaving { animation: toast-out var(--duration-base) var(--ease-in-out) forwards; }
.toast__icon { color: var(--t-accent); margin-top: 1px; }
.toast__title { font-size: var(--text-sm); font-weight: var(--weight-semibold); line-height: var(--leading-snug); }
.toast__desc { margin-top: 2px; font-size: var(--text-xs); color: var(--text-muted); line-height: var(--leading-normal); word-break: break-word; }
.toast__actions { display: flex; gap: var(--space-1-5); margin-top: var(--space-2); }
.toast__close { color: var(--text-subtle); border-radius: var(--radius-xs); padding: 2px; }
.toast__close:hover { color: var(--text); background: var(--surface-active); }
.toast--success { --t-accent: var(--success); }
.toast--warning { --t-accent: var(--warning); }
.toast--error { --t-accent: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Segmented Control ---------- */
.seg {
  display: inline-flex;
  max-width: 100%;      /* 窄屏下选项多于可用宽度时，在自身内横向滚动，不撑破页面（/growth 375px 实测溢出 5px） */
  overflow-x: auto;
  scrollbar-width: none;
  align-items: center;
  gap: 2px;
  height: 32px;
  padding: 2px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}
.seg__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);
  height: 100%;
  padding: 0 var(--space-2-5);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  transition: color var(--duration-fast) var(--ease-out), background-color var(--duration-fast) var(--ease-out);
}
.seg__item:hover { color: var(--text); }
.seg__item[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg--sm { height: 28px; }

/* ---------- Table（高密度数据表） ---------- */
.table-wrap { position: relative; overflow: auto; min-width: 0; }
.table { width: 100%; font-size: var(--text-xs); }
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 34px;
  padding: 0 var(--space-3);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.02em;
  text-align: left;
  white-space: nowrap;
  user-select: none;
}
.table th.is-sortable { cursor: pointer; }
.table th.is-sortable:hover { color: var(--text); }
.table th[aria-sort="ascending"],
.table th[aria-sort="descending"] { color: var(--text); }
.table td {
  height: 40px;
  padding: 0 var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
  vertical-align: middle;
}
.table td.cell-primary { color: var(--text); font-weight: var(--weight-medium); }
.table tbody tr { transition: background-color var(--duration-fast) var(--ease-out); }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr.is-selected { background: var(--accent-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.row-actions { opacity: 0; transition: opacity var(--duration-fast) var(--ease-out); }
.table tbody tr:hover .row-actions,
.table tbody tr:focus-within .row-actions { opacity: 1; }

.rank-num {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}
.rank-num--top { background: var(--accent-soft); color: var(--accent-soft-fg); }

/* ---------- Tooltip（纯 CSS，data-tip 属性） ----------
   方向：data-tip-side="top(默认)|bottom|right|left"
   对齐：data-tip-align="center(默认)|start|end" —— 靠近屏幕边缘的按钮用 end/start，避免提示溢出视口 */
[data-tip] { position: relative; }
[data-tip]::after {
  --tip-x: -50%;
  --tip-y: 0px;
  --tip-shift: 3px;
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  z-index: var(--z-popover);
  max-width: min(280px, 80vw);
  width: max-content;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--chart-tooltip-bg);
  color: var(--chart-tooltip-fg);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  line-height: 1.45;
  white-space: normal;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  transform: translate(var(--tip-x), calc(var(--tip-y) + var(--tip-shift)));
  transition: opacity var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after { --tip-shift: 0px; opacity: 1; transition-delay: 350ms; }
[data-tip-side="bottom"]::after { bottom: auto; top: calc(100% + 6px); --tip-shift: -3px; }
[data-tip-side="right"]::after { left: calc(100% + 8px); bottom: auto; top: 50%; --tip-x: 0px; --tip-y: -50%; --tip-shift: 0px; }
[data-tip-side="left"]::after { left: auto; right: calc(100% + 8px); bottom: auto; top: 50%; --tip-x: 0px; --tip-y: -50%; --tip-shift: 0px; }
[data-tip-align="end"]::after { left: auto; right: 0; --tip-x: 0px; }
[data-tip-align="start"]::after { left: 0; --tip-x: 0px; }
[data-tip=""]::after { display: none; }
/* 触屏设备没有悬停，提示会"粘"在屏幕上，直接关闭 */
@media (hover: none) {
  [data-tip]::after { display: none; }
}

/* ---------- 顶部请求进度条 ---------- */
.progress-bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: var(--z-toast);
  height: 2px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-out);
}
.progress-bar.is-active { opacity: 1; }
.progress-bar::before {
  content: "";
  display: block;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: ui-progress 1.1s var(--ease-in-out) infinite;
}
@keyframes ui-progress { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* ---------- 分隔线 / 列表 ---------- */
.divider { height: 1px; background: var(--border-subtle); border: 0; }
.list { display: flex; flex-direction: column; }
.list__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color var(--duration-fast) var(--ease-out);
}
.list__item:last-child { border-bottom: 0; }
.list__item:hover { background: var(--surface-hover); }

.thumb {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

/* ---------- 色板（设计系统页用） ---------- */
.swatch {
  display: flex;
  flex-direction: column;
  gap: var(--space-1-5);
  min-width: 0;
}
.swatch__chip {
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.swatch__name { font-size: var(--text-xs); font-weight: var(--weight-medium); }
.swatch__var { font-size: var(--text-2xs); color: var(--text-muted); font-family: var(--font-mono); }

.seg::-webkit-scrollbar { display: none; }
.seg__item { flex: 0 0 auto; }
