/* ============================================================
   暖屿 · 共享 UI 层（nx-*）
   纯增量：只新增类名，不用元素选择器覆盖既有页面样式。
   ============================================================ */

:root {
  --nx-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --nx-brand: #3B82F6;
  --nx-brand-2: #8B5CF6;
  --nx-grad: linear-gradient(135deg, #3B82F6, #8B5CF6);
  --nx-ink: #1f2937;
  --nx-ink-sub: #6b7280;
  --nx-line: rgba(15, 23, 42, 0.08);
  --nx-card: #ffffff;
  --nx-r: 16px;
  --nx-r-sm: 10px;
  --nx-shadow-1: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 26px -14px rgba(15, 23, 42, 0.16);
  --nx-shadow-2: 0 14px 34px -16px rgba(37, 99, 235, 0.45);
}

/* ---------- 焦点可见性（零特异性，页面可覆盖） ---------- */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid rgba(59, 130, 246, 0.75);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- 交互按压反馈（零特异性，页面自定义优先） ---------- */
:where(button, .btn-primary, .btn-danger, .btn-default, .nav-tab, .filter-tag, .entry-btn):active {
  transform: scale(0.97);
}

/* ============================================================
   1. 卡片 / 面板
   ============================================================ */
.nx-card {
  background: var(--nx-card);
  border: 1px solid var(--nx-line);
  border-radius: var(--nx-r);
  box-shadow: var(--nx-shadow-1);
}

.nx-card-hover {
  transition: transform 0.32s var(--nx-ease), box-shadow 0.32s var(--nx-ease), border-color 0.32s var(--nx-ease);
}
.nx-card-hover:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 40px -22px rgba(37, 99, 235, 0.45);
  border-color: rgba(59, 130, 246, 0.35);
}

/* 分区容器：标题 + 内容 */
.nx-panel {
  background: var(--nx-card);
  border: 1px solid var(--nx-line);
  border-radius: var(--nx-r);
  padding: 18px 18px 8px;
  margin-bottom: 20px;
}

.nx-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

/* 分区标题：左侧渐变小竖条 */
.nx-sec-title {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding-left: 12px;
  font-size: 16px;
  font-weight: 800;
  color: var(--nx-ink);
  line-height: 1.4;
}
.nx-sec-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 4px;
  height: 18px;
  margin-top: -9px;
  border-radius: 4px;
  background: var(--nx-grad);
}

.nx-count-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.1);
  color: #2563eb;
  font-size: 12px;
  font-weight: 800;
}

/* ============================================================
   2. KPI 指标卡
   ============================================================ */
.nx-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.nx-kpi {
  position: relative;
  overflow: hidden;
  padding: 16px 18px;
  border-radius: var(--nx-r);
  border: 1px solid var(--nx-line);
  background: var(--nx-card);
  box-shadow: var(--nx-shadow-1);
  transition: transform 0.32s var(--nx-ease), box-shadow 0.32s var(--nx-ease);
}
.nx-kpi::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--nx-accent, var(--nx-grad));
}
.nx-kpi:hover {
  transform: translateY(-2px);
  box-shadow: var(--nx-shadow-2);
}

.nx-kpi-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--nx-ink-sub);
  margin-bottom: 8px;
  letter-spacing: 0.2px;
}

.nx-kpi-value {
  font-size: 27px;
  font-weight: 900;
  line-height: 1.15;
  color: var(--nx-ink);
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  word-break: normal;
  overflow-wrap: anywhere;
}
.nx-kpi-value .nx-unit {
  font-size: 13px;
  font-weight: 700;
  color: var(--nx-ink-sub);
  margin-left: 3px;
}

.nx-kpi-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--nx-ink-sub);
}

/* KPI 配色（通过 --nx-accent + 文字色） */
.nx-kpi--blue   { --nx-accent: linear-gradient(180deg, #3B82F6, #60a5fa); background: linear-gradient(135deg, #f7faff, #eff6ff); }
.nx-kpi--blue   .nx-kpi-value { color: #1e3a8a; }
.nx-kpi--green  { --nx-accent: linear-gradient(180deg, #10b981, #34d399); background: linear-gradient(135deg, #f6fffb, #ecfdf5); }
.nx-kpi--green  .nx-kpi-value { color: #064e3b; }
.nx-kpi--red    { --nx-accent: linear-gradient(180deg, #ef4444, #f87171); background: linear-gradient(135deg, #fff8f8, #fef2f2); }
.nx-kpi--red    .nx-kpi-value { color: #7f1d1d; }
.nx-kpi--violet { --nx-accent: linear-gradient(180deg, #8B5CF6, #a78bfa); background: linear-gradient(135deg, #fbf9ff, #f5f3ff); }
.nx-kpi--violet .nx-kpi-value { color: #4c1d95; }
.nx-kpi--amber  { --nx-accent: linear-gradient(180deg, #f59e0b, #fbbf24); background: linear-gradient(135deg, #fffcf5, #fffbeb); }
.nx-kpi--amber  .nx-kpi-value { color: #78350f; }

/* ============================================================
   3. 参数配置区（原本挤成一行的输入区）
   ============================================================ */
.nx-params {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 14px 16px;
  border-radius: var(--nx-r);
  border: 1px solid #fecaca;
  background: #fef7f7;
  margin-bottom: 20px;
}

.nx-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #b91c1c;
  white-space: nowrap;
}
.nx-field input,
.nx-field select {
  padding: 7px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  background: #fff;
  color: var(--nx-ink);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.nx-field input { width: 76px; }
.nx-field input[type="number"] { width: 68px; text-align: center; }
.nx-field input:focus,
.nx-field select:focus {
  border-color: #f87171;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.15);
  outline: none;
}

.nx-params-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

/* ============================================================
   4. 轻量标签 / 按钮修饰
   ============================================================ */
.nx-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--nx-line);
  background: #fff;
  color: var(--nx-ink-sub);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.22s var(--nx-ease);
}
.nx-chip:hover { border-color: rgba(59, 130, 246, 0.4); color: #2563eb; }
.nx-chip.is-on {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.45);
  color: #1d4ed8;
}

.nx-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.nx-dot--live { background: #22c55e; animation: nxLivePulse 2s infinite; }
@keyframes nxLivePulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* 数字刷新时的高亮脉冲（JS: nxFlash） */
.nx-flash { animation: nxFlash 0.7s var(--nx-ease); }
@keyframes nxFlash {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); filter: brightness(1.15); }
  100% { transform: scale(1); }
}

/* ============================================================
   5. 滚动渐入（需 JS 添加 html.nx-js，避免无 JS 时内容不可见）
   ============================================================ */
html.nx-js .nx-reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.5s var(--nx-ease), transform 0.5s var(--nx-ease);
  transition-delay: calc(var(--nx-i, 0) * 45ms);
  will-change: opacity, transform;
}
html.nx-js .nx-reveal.nx-in {
  opacity: 1;
  transform: none;
}

/* ============================================================
   6. 骨架屏
   ============================================================ */
.nx-skeleton {
  position: relative;
  overflow: hidden;
  background: #eef1f5;
  border-radius: 8px;
  color: transparent !important;
}
.nx-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.75), transparent);
  animation: nxShimmer 1.4s infinite;
}
@keyframes nxShimmer { 100% { transform: translateX(100%); } }

/* ============================================================
   7. 横向滑动条（移动端标签栏）
   ============================================================ */
.nx-scroll-x {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.nx-scroll-x::-webkit-scrollbar { display: none; }
.nx-scroll-x > * { scroll-snap-align: start; flex: 0 0 auto; }

/* ============================================================
   8. 移动端适配
   ============================================================ */
@media (max-width: 640px) {
  .nx-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
  }
  .nx-kpi { padding: 13px 12px; border-radius: 14px; }
  .nx-kpi::after { width: 3px; }
  .nx-kpi-label { font-size: 12px; margin-bottom: 6px; }
  .nx-kpi-value { font-size: 19px; letter-spacing: -0.2px; }
  .nx-kpi-value .nx-unit { font-size: 11px; }
  .nx-kpi-sub { font-size: 11px; }

  .nx-panel { padding: 14px 12px 6px; border-radius: 14px; margin-bottom: 14px; }
  .nx-sec-title { font-size: 15px; padding-left: 10px; }
  .nx-sec-title::before { height: 15px; margin-top: -7.5px; }

  .nx-params { padding: 12px; gap: 10px; }
  .nx-field { font-size: 12.5px; }
  .nx-field input, .nx-field select { font-size: 15px; padding: 8px 10px; }
  .nx-params-actions { margin-left: 0; width: 100%; }
  .nx-params-actions > * { flex: 1 1 auto; }

  /* 触控目标不小于 40px */
  .nx-chip { padding: 8px 14px; font-size: 13px; }
}

/* 极窄屏：KPI 单列更易读 */
@media (max-width: 360px) {
  .nx-kpi-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   9. 暗色主题（后台 data-theme="dark"）
   ============================================================ */
[data-theme="dark"] {
  --nx-ink: #f3f4f6;
  --nx-ink-sub: #9ca3af;
  --nx-line: #374151;
  --nx-card: #1f2937;
  --nx-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 26px -16px rgba(0, 0, 0, 0.6);
}
[data-theme="dark"] .nx-kpi { background: #1f2937; border-color: #374151; }
[data-theme="dark"] .nx-kpi--blue   { background: linear-gradient(135deg, #17253c, #1b2b44); }
[data-theme="dark"] .nx-kpi--green  { background: linear-gradient(135deg, #122b22, #143026); }
[data-theme="dark"] .nx-kpi--red    { background: linear-gradient(135deg, #331b1b, #3a1f1f); }
[data-theme="dark"] .nx-kpi--violet { background: linear-gradient(135deg, #251c3a, #2a2040); }
[data-theme="dark"] .nx-kpi--amber  { background: linear-gradient(135deg, #302415, #382a19); }
[data-theme="dark"] .nx-kpi--blue   .nx-kpi-value { color: #bfdbfe; }
[data-theme="dark"] .nx-kpi--green  .nx-kpi-value { color: #a7f3d0; }
[data-theme="dark"] .nx-kpi--red    .nx-kpi-value { color: #fecaca; }
[data-theme="dark"] .nx-kpi--violet .nx-kpi-value { color: #ddd6fe; }
[data-theme="dark"] .nx-kpi--amber  .nx-kpi-value { color: #fde68a; }
[data-theme="dark"] .nx-kpi-label { color: #cbd5e1; }
[data-theme="dark"] .nx-panel { background: #1f2937; border-color: #374151; }
[data-theme="dark"] .nx-sec-title { color: #f3f4f6; }
[data-theme="dark"] .nx-params { background: #2a1f22; border-color: #573236; }
[data-theme="dark"] .nx-field { color: #fca5a5; }
[data-theme="dark"] .nx-field input,
[data-theme="dark"] .nx-field select { background: #374151; border-color: #4b5563; color: #f3f4f6; }
[data-theme="dark"] .nx-chip { background: #1f2937; border-color: #374151; color: #9ca3af; }
[data-theme="dark"] .nx-skeleton { background: #374151; }
[data-theme="dark"] .nx-skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.12), transparent); }

/* ============================================================
   10. 无障碍：减弱动效
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  html.nx-js .nx-reveal { opacity: 1; transform: none; transition: none; }
  .nx-card-hover:hover,
  .nx-kpi:hover { transform: none; }
  .nx-dot--live,
  .nx-flash,
  .nx-skeleton::after { animation: none !important; }
}

/* ============================================================
   11. 前台动效层（nx-fx-*）
   纯增量：只新增类名与装饰图层；隐藏态由 JS 加类后才生效，
   JS 不执行时页面内容保持原样可见。
   ============================================================ */
:root {
  --nx-fx-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --nx-fx-glow: rgba(59, 130, 246, 0.16);
  --nx-fx-ring-a: rgba(59, 130, 246, 0.65);
  --nx-fx-ring-b: rgba(139, 92, 246, 0.6);
  --nx-fx-ring-c: rgba(236, 72, 153, 0.5);
  --nx-ripple-c: rgba(59, 130, 246, 0.16);
}
[data-theme="dark"] {
  --nx-fx-glow: rgba(96, 165, 250, 0.14);
  --nx-ripple-c: rgba(255, 255, 255, 0.2);
}

/* ---------- 11.1 滚动逐张入场 ---------- */
html.nx-js .nx-fx {
  opacity: 0;
  transform: translate3d(0, 16px, 0) scale(0.985);
  transition: opacity 0.52s var(--nx-fx-ease), transform 0.52s var(--nx-fx-ease);
  transition-delay: calc(var(--nx-i, 0) * 60ms);
  will-change: opacity, transform;
}
html.nx-js .nx-fx.nx-fx-in {
  opacity: 1;
  transform: none;
  will-change: auto;
}
/* 视口外卡片：关闭页面原有的一次性入场动画，改由共享层在滚动到视口时播放 */
.nx-fx-defer { animation: none !important; }

/* ---------- 11.2 全站滚动进度条 ---------- */
.nx-progress {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  height: 3px;
  z-index: 99998;
  pointer-events: none;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: linear-gradient(90deg, #3B82F6 0%, #8B5CF6 60%, #EC4899 100%);
  box-shadow: 0 2px 10px -2px rgba(99, 102, 241, 0.55);
  opacity: 0;
  transition: opacity 0.25s ease;
  will-change: transform;
}
.nx-progress.on { opacity: 1; }

/* ---------- 11.3 图片淡入 ---------- */
.nx-img-fade { opacity: 0 !important; }
.nx-img-fade.nx-img-in { opacity: 1 !important; transition: opacity 0.45s ease; }

/* ---------- 11.4 顶栏滚动状态（不改变高度，避免与各页内联 padding 冲突） ---------- */
header, .header { transition: box-shadow 0.32s ease, border-color 0.32s ease; }
header.nx-fx-scrolled,
.header.nx-fx-scrolled {
  box-shadow: 0 10px 28px -20px rgba(15, 23, 42, 0.6) !important;
  border-bottom-color: rgba(15, 23, 42, 0.12) !important;
}
[data-theme="dark"] header.nx-fx-scrolled,
[data-theme="dark"] .header.nx-fx-scrolled {
  box-shadow: 0 10px 28px -16px rgba(0, 0, 0, 0.85) !important;
  border-bottom-color: rgba(255, 255, 255, 0.08) !important;
}

/* ---------- 11.5 桌面端交互（仅 hover 精确指针，移动端完全不加载） ---------- */
@media (hover: hover) and (pointer: fine) {
  .nx-fx-glow { position: relative; }
  .nx-fx-glow::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.35s ease;
    background: radial-gradient(240px circle at var(--nx-mx, 50%) var(--nx-my, 50%), var(--nx-fx-glow), transparent 62%);
  }
  .nx-fx-glow:hover::after { opacity: 1; }

  .banner-btn,
  .btn-primary,
  #navLoginBtn,
  .filter-tag.active { --nx-ripple-c: rgba(255, 255, 255, 0.45); }
}

/* 渐变描边流光：仅在支持 mask 合成的浏览器启用，否则整段无效（降级为无描边） */
@supports ((-webkit-mask-composite: xor) or (mask-composite: exclude)) {
  @media (hover: hover) and (pointer: fine) {
    .nx-fx-ring::before {
      content: "";
      position: absolute;
      inset: 0;
      z-index: 2;
      border-radius: inherit;
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.35s ease;
      padding: 1.5px;
      background: linear-gradient(120deg, var(--nx-fx-ring-a), var(--nx-fx-ring-b) 48%, var(--nx-fx-ring-c));
      -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
      mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
      -webkit-mask-composite: xor;
      mask-composite: exclude;
    }
    .nx-fx-ring:hover::before,
    .nx-fx-ring:focus-visible::before { opacity: 1; }
  }
}

/* ---------- 11.6 无障碍：减弱动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  html.nx-js .nx-fx { opacity: 1; transform: none; transition: none; }
  .nx-img-fade { opacity: 1 !important; }
  .nx-fx-glow::after,
  .nx-fx-ring::before { display: none; }
  .nx-progress { display: none; }
}
