/* ==========================================================================
   全站统一顶栏规范 + 明暗主题 token
   单一事实来源：所有页面（React 各页 / 独立 Vue 选型页）共用本文件。
   通过 <link rel="stylesheet" href="/theme/app-nav.css"> 引入，且必须在各页
   自身样式之前，页面样式可覆盖细节但不该改几何（高度/圆角/间距/阴影）。
   顶栏结构约定：
     <header class="app-nav">            ← 悬浮容器（fixed，透明，负责留边）
       <div class="app-nav-inner">       ← 胶囊本体（几何唯一来源）
         <a class="app-brand">…          ← 左：品牌
         <div class="app-nav-center">…   ← 中：页面标题或导航
         <div class="app-nav-actions">…  ← 右：操作区（含夜间模式按钮）
       </div>
     </header>
   ========================================================================== */

:root {
  /* 顶栏几何：全站唯一 */
  --nav-height: 64px;
  --nav-max: 1160px;
  --nav-top: 14px;
  --nav-gap: 16px;
  --nav-radius: 999px;

  /* 顶栏配色（浅色） */
  --nav-surface: rgba(255, 255, 255, 0.92);
  --nav-surface-strong: rgba(255, 255, 255, 0.97);
  --nav-line: rgba(226, 233, 241, 0.9);
  --nav-ink: #0f172a;
  --nav-ink-2: #46586e;
  --nav-muted: #7b8ea6;
  --nav-brand: #2563eb;
  --nav-primary: #1c2634;
  --nav-primary-hover: #2a3a4f;
  --nav-primary-ink: #f8fbff;
  --nav-hover: #eef3f9;
  --nav-shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
  --nav-shadow-strong: 0 12px 32px rgba(15, 23, 42, 0.12);
  --nav-shadow-primary: 0 6px 16px rgba(28, 38, 52, 0.24);
  --nav-focus: rgba(37, 99, 235, 0.38);
  --nav-success: #3cb878;

  /* 页面底色（供各页在深色下复用） */
  --page-bg: #f3f8ff;
  --page-bg-2: #e8f2fc;
  --page-surface: #ffffff;
  --page-line: #dde7f2;
  --page-ink: #0f172a;
  --page-ink-2: #46586e;
  --page-muted: #7b8ea6;
}

html[data-theme='dark'] {
  --nav-surface: rgba(17, 25, 39, 0.86);
  --nav-surface-strong: rgba(17, 25, 39, 0.96);
  --nav-line: rgba(58, 76, 102, 0.72);
  --nav-ink: #e9eff8;
  --nav-ink-2: #b6c4d8;
  --nav-muted: #8598b0;
  --nav-brand: #7fb0ff;
  --nav-primary: #3b82f6;
  --nav-primary-hover: #5b9bff;
  --nav-primary-ink: #04101f;
  --nav-hover: rgba(255, 255, 255, 0.09);
  --nav-shadow: 0 4px 20px rgba(0, 0, 0, 0.42);
  --nav-shadow-strong: 0 14px 36px rgba(0, 0, 0, 0.56);
  --nav-shadow-primary: 0 6px 18px rgba(21, 101, 216, 0.4);
  --nav-focus: rgba(127, 176, 255, 0.5);
  --nav-success: #34c98a;

  --page-bg: #0b1220;
  --page-bg-2: #0e1728;
  --page-surface: #131d2e;
  --page-line: #26324a;
  --page-ink: #e9eff8;
  --page-ink-2: #b6c4d8;
  --page-muted: #8598b0;
}

html[data-theme='dark'] {
  color-scheme: dark;
  background: var(--page-bg);
}

/* --------------------------------------------------------------------------
   顶栏容器
   -------------------------------------------------------------------------- */
.app-nav {
  position: fixed;
  top: var(--nav-top);
  left: 0;
  right: 0;
  z-index: 60;
  padding: 0 16px;
  background: transparent;
  border: 0;
  box-shadow: none;
  color: var(--nav-ink);
  font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
}

.app-nav-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--nav-gap);
  box-sizing: border-box;
  max-width: var(--nav-max);
  min-height: var(--nav-height);
  margin: 0 auto;
  padding: 0 10px 0 14px;
  background: var(--nav-surface);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border: 1px solid var(--nav-line);
  border-radius: var(--nav-radius);
  box-shadow: var(--nav-shadow);
  transition: box-shadow 0.25s ease, background-color 0.25s ease, border-color 0.25s ease;
}

/* 滚动后：阴影加深 + 底更实（全站统一阈值 24px，由各页给出 is-scrolled） */
.app-nav.is-scrolled .app-nav-inner {
  background: var(--nav-surface-strong);
  box-shadow: var(--nav-shadow-strong);
}

/* --------------------------------------------------------------------------
   品牌
   -------------------------------------------------------------------------- */
.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--nav-ink);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.25;
  text-decoration: none;
}

.app-brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--nav-primary);
  color: #ffffff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.5px;
}

html[data-theme='dark'] .app-brand-mark {
  color: var(--nav-primary-ink);
}

.app-brand-copy {
  display: grid;
  min-width: 0;
}

.app-brand-copy strong {
  color: var(--nav-ink);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-brand-copy small {
  margin-top: 3px;
  color: var(--nav-muted);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------------------------------
   中栏（导航；页面名称标题已于 2026-09-12 下线，不再显示）
   -------------------------------------------------------------------------- */
.app-nav-center {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  color: var(--nav-muted);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

/* 没有中栏的页面（选型/个人中心/批量查询/支付/商城）：网格收成两列，
   品牌吃左列、操作区靠右；有中栏的首页主导航仍走上面的三列规则。
   窄屏规则在下方 media 里，需要同步带上这个选择器才能压过本规则。 */
.app-nav-inner:not(:has(.app-nav-center)) {
  grid-template-columns: minmax(0, 1fr) auto;
}

.app-nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.app-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--nav-radius);
  background: transparent;
  color: var(--nav-ink-2);
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.app-nav-link:hover {
  background: var(--nav-hover);
  color: var(--nav-ink);
}

.app-nav-link.is-active {
  color: var(--nav-brand);
}

/* --------------------------------------------------------------------------
   右侧操作区
   -------------------------------------------------------------------------- */
.app-nav-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.app-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--nav-radius);
  background: transparent;
  color: var(--nav-ink-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease,
    box-shadow 0.16s ease, transform 0.16s ease;
}

.app-nav-btn:hover {
  background: var(--nav-hover);
  color: var(--nav-ink);
  transform: translateY(-1px);
}

.app-nav-btn:active {
  transform: translateY(0);
}

.app-nav-btn-primary,
.app-nav-btn-primary:hover {
  color: var(--nav-primary-ink);
}

.app-nav-btn-primary {
  background: var(--nav-primary);
  box-shadow: var(--nav-shadow-primary);
}

.app-nav-btn-primary:hover {
  background: var(--nav-primary-hover);
  box-shadow: 0 8px 20px rgba(28, 38, 52, 0.3);
}

html[data-theme='dark'] .app-nav-btn-primary:hover {
  box-shadow: 0 8px 22px rgba(21, 101, 216, 0.5);
}

.app-nav-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 6px;
  color: var(--nav-ink-2);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.app-nav-user b {
  font-weight: 800;
  color: var(--nav-ink);
}

.app-nav-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--nav-success);
  box-shadow: 0 0 0 4px rgba(60, 184, 120, 0.18);
}

.app-nav-dot.is-busy {
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
}

.app-nav-dot.is-error {
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2);
}

/* --------------------------------------------------------------------------
   夜间模式按钮（全站同一位置：操作区首个元素）
   -------------------------------------------------------------------------- */
.app-theme-toggle {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--nav-line);
  border-radius: var(--nav-radius);
  background: transparent;
  color: var(--nav-ink-2);
  cursor: pointer;
  transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease,
    transform 0.16s ease;
}

.app-theme-toggle:hover {
  background: var(--nav-hover);
  color: var(--nav-ink);
  transform: translateY(-1px);
}

.app-theme-toggle svg {
  display: block;
  width: 18px;
  height: 18px;
}

/* 注意选择器要带上 .app-theme-toggle，否则会被上面的 svg{display:block} 盖掉 */
.app-theme-toggle .app-theme-icon-sun {
  display: none;
}

html[data-theme='dark'] .app-theme-toggle .app-theme-icon-sun {
  display: block;
}

html[data-theme='dark'] .app-theme-toggle .app-theme-icon-moon {
  display: none;
}

/* 顶栏里的次级操作统一为幽灵样式：页面级样式给它加的实心底色（如首页的橙色
   「个人中心」）在顶栏里一律不生效，保证各页操作区层级一致。
   ⚠️ 必须同时把 color 一起归一：页面级样式配橙色底写的是 color:#ffffff，
   只重置 background 的话会变成「白字 + 浅色顶栏」= 肉眼看不见（2026-09-10 修）。
   第二条是为了压过 styles.css 的 `.site-header.is-scrolled .workspace-link`
   （滚动后强制白字，特异性 0,3,0）。注意 .site-header 和 .app-nav 是同一个元素，
   不能写成 `.app-nav .site-header…`（那是后代选择器，永不匹配），要写成 `.app-nav.is-scrolled`。 */
.app-nav .workspace-link,
.app-nav.is-scrolled .app-nav-actions .workspace-link {
  background: transparent;
  box-shadow: none;
  color: var(--nav-ink-2);
}

.app-nav .workspace-link:hover,
.app-nav.is-scrolled .app-nav-actions .workspace-link:hover {
  background: var(--nav-hover);
  color: var(--nav-ink);
}

/* --------------------------------------------------------------------------
   焦点环（键盘可达性，全站一致）
   -------------------------------------------------------------------------- */
.app-nav a:focus-visible,
.app-nav button:focus-visible {
  outline: 3px solid var(--nav-focus);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   窄屏：保持胶囊形态，操作区与导航横向滑动（双指/滚轮横滑），
   滚动条隐藏、带吸附，页面之间表现一致。
   -------------------------------------------------------------------------- */
.app-nav-actions,
.app-nav-links {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.app-nav-actions::-webkit-scrollbar,
.app-nav-links::-webkit-scrollbar {
  display: none;
}

@media (max-width: 900px) {
  .app-nav {
    top: 10px;
    padding: 0 10px;
  }

  /* 品牌列 auto、操作列吃掉剩余宽度：操作区一旦超出就在胶囊内部横向滑动，
     不能让它把胶囊撑破（auto + auto 会让两列都按内容宽度撑开）。 */
  .app-nav-inner,
  .app-nav-inner:not(:has(.app-nav-center)) {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    min-height: 58px;
    padding: 0 8px 0 10px;
  }

  .app-nav-center {
    display: none;
  }

  /* 可横向滚动时不能用 justify-content:flex-end：内容会向左侧溢出且滚不回来
     （表现为操作区盖住品牌）。改成「首个元素 margin-left:auto」——
     有剩余空间时等效右对齐，内容超出时自动归零、从左边开始正常滑动。 */
  .app-nav-actions {
    /* justify-self:end 会让网格项按「内容宽度」而不是列宽渲染 → 内容宽时
       向左溢出把品牌盖住。窄屏必须改成 stretch，让列宽决定宽度。 */
    justify-self: stretch;
    justify-content: flex-start;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  .app-nav-actions > :first-child {
    margin-left: auto;
  }

  .app-nav-actions > * {
    scroll-snap-align: end;
  }

  .app-nav-links {
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  .app-nav-links > * {
    scroll-snap-align: start;
  }
}

@media (max-width: 560px) {
  .app-brand-copy small {
    display: none;
  }

  .app-nav-btn {
    padding: 0 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-nav-inner,
  .app-nav-btn,
  .app-nav-link,
  .app-theme-toggle {
    transition: none;
  }
}
