/* ==========================================================================
   统一外壳（Shell）样式
   --------------------------------------------------------------------------
   规则约束（契约 v1）：
   1. 只写 .sh* 类名；不覆盖 .btn / .card / .navbar 等既有组件类。
   2. 不新增任何颜色令牌，全部复用 tools.css 已有的 --color-* 语义令牌。
   3. 深色适配统一走 html[data-theme="dark"] .sh-...，不使用
      @media (prefers-color-scheme) 另起一套。
   4. 细顶栏：52px（桌面）/ 48px（≤720px），sticky，无毛玻璃、无阴影。
   ========================================================================== */

:root {
  /* 外壳高度：shell.js 会在运行时用实测值覆写，供页面内 sticky 元素让位 */
  --sh-height: 52px;
}

/* --------------------------------------------------------------------------
   1. 外壳容器
   -------------------------------------------------------------------------- */
.sh {
  position: sticky;
  top: 0;
  z-index: 100;
  flex: 0 0 auto;
  height: var(--sh-height);
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border-subtle);
  /* 契约明确：不用毛玻璃、不用阴影 */
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  line-height: 1.4;
}

.sh-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  min-width: 0;
}

/* --------------------------------------------------------------------------
   2. 左：Brand
   -------------------------------------------------------------------------- */
.sh-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  min-width: 0;
  padding: 4px 2px;
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-weight: 600;
  text-decoration: none;
  transition: opacity 150ms ease;
}

.sh-brand:hover {
  color: var(--color-text-primary);
  opacity: 0.82;
}

.sh-brand:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.sh-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}

.sh-brand-text {
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   3. 中：返回按钮
   -------------------------------------------------------------------------- */
.sh-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  height: 32px;
  padding: 0 10px 0 6px;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.sh-back:hover {
  background: var(--color-bg-subtle);
  border-color: var(--color-border-strong);
  color: var(--color-text-primary);
}

.sh-back:active {
  background: var(--color-bg-hover);
}

.sh-back:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.sh-back svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------------------
   4. 中：面包屑（可伸缩、超长省略）
   -------------------------------------------------------------------------- */
.sh-crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  color: var(--color-text-secondary);
}

.sh-crumbs a {
  flex: 0 0 auto;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 150ms ease;
}

.sh-crumbs a:hover {
  color: var(--color-primary);
}

.sh-crumbs a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

.sh-sep {
  flex: 0 0 auto;
  color: var(--color-text-muted);
}

.sh-group {
  flex: 0 0 auto;
  color: var(--color-text-secondary);
}

.sh-current {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-text-primary);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   5. 右：操作区
   -------------------------------------------------------------------------- */
.sh-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

.sh-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: var(--color-bg-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

.sh-icon:hover {
  background: var(--color-bg-subtle);
  border-color: var(--color-border-strong);
  color: var(--color-text-primary);
}

.sh-icon:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.sh-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------------------
   6. 深色：令牌本身已随 [data-theme="dark"] 切换，此处只做显式兜底
   -------------------------------------------------------------------------- */
html[data-theme="dark"] .sh {
  background: var(--color-bg-surface);
  border-bottom-color: var(--color-border-subtle);
  box-shadow: none;
}

html[data-theme="dark"] .sh-logo {
  color: var(--color-text-inverse);
}

html[data-theme="dark"] .sh-back,
html[data-theme="dark"] .sh-icon {
  background: transparent;
  border-color: var(--color-border-subtle);
  color: var(--color-text-secondary);
}

html[data-theme="dark"] .sh-icon {
  background: var(--color-bg-surface);
}

html[data-theme="dark"] .sh-back:hover,
html[data-theme="dark"] .sh-icon:hover {
  background: var(--color-bg-subtle);
  border-color: var(--color-border-strong);
  color: var(--color-text-primary);
}

/* --------------------------------------------------------------------------
   7. 移动端 ≤720px：只留 logo 方块 + 当前页名 + 返回 + 主题
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
  :root {
    --sh-height: 48px;
  }

  .sh-inner {
    gap: 6px;
    padding: 0 14px;
  }

  /* 品牌文字隐藏，只保留方块 logo */
  .sh-brand-text {
    display: none;
  }

  /* 面包屑只留当前页名：隐藏链接层、分组层与其分隔符 */
  .sh-crumbs {
    gap: 0;
  }

  .sh-crumbs a,
  .sh-crumbs .sh-group,
  .sh-crumbs .sh-sep {
    display: none;
  }

  .sh-current {
    max-width: 100%;
  }

  /* 触控友好：所有可点元素至少 44px */
  .sh-brand {
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  .sh-back {
    min-height: 44px;
    height: auto;
  }

  .sh-icon {
    min-width: 44px;
    min-height: 44px;
    width: auto;
    height: auto;
  }

  .sh-actions {
    gap: 4px;
  }
}

/* --------------------------------------------------------------------------
   7b. 平板 721–900px：隐藏分组层，保留「工具台 / 当前页」
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .sh-group,
  .sh-crumbs .sh-sep:first-of-type {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   8. 必要重置：外壳自己就是 sticky，页面无需再为旧 navbar 留顶部位移
   -------------------------------------------------------------------------- */
body {
  padding-top: 0;
}

/* 外壳本身不是 flex 容器，避免与页面 body{display:flex} 布局互相干扰 */
body > .sh {
  width: 100%;
}

/* 锚点跳转时不要让目标被 sticky 外壳盖住 */
html {
  scroll-padding-top: calc(var(--sh-height) + 8px);
}
