/* 应用外壳样式（顶栏 / 主导航 / 用户菜单 / 页脚 / 底部标签栏 / 面包屑）。
 *
 * 颜色、间距、圆角、动效一律取 `tokens.css` 的令牌，本文件不出现硬编码色值。
 * 断点三档与 `base.css` 一致：≤639px 移动 / 640–1023px 平板 / ≥1024px 桌面。
 */

/* --- 通用 --- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  transform: translateY(-200%);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

/* --- 顶栏 --- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--ink-950);
  color: var(--surface);
}

.app-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: 64px;
}

.brand {
  flex: none;
  color: var(--surface);
  font-size: var(--text-h4);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.brand:hover {
  color: var(--brand-100);
}

.brand__short {
  display: none;
}

.app-nav {
  flex: 0 1 auto;
  min-width: 0;
  margin-left: auto;
}

.app-nav ul {
  display: flex;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-nav li {
  margin: 0;
}

.app-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--ink-300);
  text-decoration: none;
  transition: color var(--duration-fast) var(--easing-standard);
}

.app-nav a:hover {
  color: var(--surface);
}

.app-nav a[aria-current="page"] {
  color: var(--surface);
  background: var(--brand-700);
}

.app-header :focus-visible {
  outline-color: var(--surface);
}

.app-header__actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
}

/* 搜索框：桌面展开，移动端收起为图标 */
.app-search {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding-left: var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-pill);
}

.app-search input {
  width: 180px;
  min-height: var(--tap-target);
  padding: 0;
  color: var(--ink-900);
  font: inherit;
  font-size: var(--text-summary);
  background: transparent;
  border: 0;
}

.app-search input::placeholder {
  color: var(--ink-500);
}

.app-search input:focus-visible {
  outline: none;
}

/* 输入框自身不画描边，改由容器给整组控件一个可见焦点环 */
.app-search:focus-within {
  outline: 2px solid var(--surface);
  outline-offset: 2px;
}

.app-search .app-icon-button {
  color: var(--ink-700);
}

/* 图标按钮：触控目标 ≥ 44×44px */
.app-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-target);
  height: var(--tap-target);
  padding: 0;
  color: var(--ink-300);
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color var(--duration-fast) var(--easing-standard);
}

.app-icon-button:hover {
  color: var(--surface);
}

/* 移动端搜索入口：桌面的搜索框已含提交按钮，这个链接只在 ≤639px 顶栏收起搜索框后出现。
 * 用双类选择器提高特异性，否则会被上面的 `.app-icon-button { display: inline-flex }` 覆盖而常显。 */
.app-icon-button.app-search-link {
  display: none;
}

/* 消息铃铛的未读角标（US-023）：数字由服务端渲染，0 条时模板不输出这个元素。
 * 定位相对铃铛锚点，占位不参与布局，因此不会把用户菜单挤偏。 */
.app-bell {
  position: relative;
}

.app-bell__badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  padding: 0 var(--space-1);
  color: var(--surface);
  font-size: var(--text-small);
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  background: var(--danger-600);
  border-radius: var(--radius-pill);
}

/* 用户菜单 */
.user-menu {
  position: relative;
}

.user-menu__summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: 0 var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  list-style: none;
}

.user-menu__summary::-webkit-details-marker {
  display: none;
}

.user-menu__summary:hover {
  background: var(--brand-700);
}

.avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--ink-950);
  font-size: var(--text-small);
  font-weight: 600;
  background: var(--brand-100);
  border-radius: var(--radius-pill);
}

.user-menu__label {
  max-width: 8em;
  overflow: hidden;
  color: var(--ink-300);
  font-size: var(--text-summary);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu__panel {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  min-width: 160px;
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.user-menu__panel a,
.user-menu__panel p {
  display: block;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  color: var(--ink-700);
  border-radius: var(--radius-sm);
  font-size: var(--text-summary);
  text-decoration: none;
}

.user-menu__panel a:hover {
  background: var(--brand-100);
  color: var(--brand-700);
}

/* 底部标签栏：桌面与平板隐藏，只在移动端出现（规则见文件末尾的 639px 媒体查询） */
.tabbar {
  display: none;
}

/* --- 内容区与页脚 --- */

.app-main {
  min-height: 60vh;
  padding-block: var(--space-6);
}

/* 移动端给底部标签栏让位 */
@media (max-width: 639px) {
  .app-main {
    padding-bottom: calc(var(--space-7) + env(safe-area-inset-bottom));
  }
}

.app-footer {
  padding-block: var(--space-5) var(--space-6);
  color: var(--ink-500);
  font-size: var(--text-small);
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.app-footer__note {
  margin: 0;
}

/* --- 面包屑 --- */

.breadcrumbs {
  margin-bottom: var(--space-4);
  font-size: var(--text-small);
}

.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.breadcrumbs li {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin: 0;
  color: var(--ink-500);
}

.breadcrumbs li + li::before {
  content: "/";
  color: var(--ink-300);
}

.breadcrumbs a {
  color: var(--ink-500);
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--brand-700);
  text-decoration: underline;
}

/* --- 底部标签栏（仅移动端） --- */

@media (max-width: 639px) {
  .app-header__inner {
    min-height: 56px;
    gap: var(--space-2);
  }

  .brand {
    flex: 1 1 auto;
    overflow: hidden;
    font-size: var(--text-body);
    text-overflow: ellipsis;
  }

  .brand__full {
    display: none;
  }

  .brand__short {
    display: inline;
  }

  .app-nav,
  .app-search,
  .user-menu__label {
    display: none;
  }

  .app-icon-button.app-search-link {
    display: inline-flex;
  }

  .tabbar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 5;
    display: block;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--line);
  }

  .tabbar ul {
    display: flex;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .tabbar li {
    flex: 1 1 0;
    margin: 0;
  }

  .tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--tap-target);
    padding: var(--space-1) 0;
    color: var(--ink-500);
    font-size: var(--text-small);
    text-decoration: none;
  }

  .tabbar a[aria-current="page"] {
    color: var(--brand-700);
  }

  .user-menu__panel {
    right: 0;
  }
}

/* 平板：保留顶栏导航，搜索框收窄（US-062：640–641px 顶栏不留横向滚动，
 * 档位起点上放不下 130px 输入框，收到 60px；更宽的平板档不受影响）。 */
@media (min-width: 640px) and (max-width: 1023px) {
  .app-search input {
    width: 60px;
  }

  .app-nav a {
    padding: 0 var(--space-2);
  }
}

/* 平板低段（640–719px）：带宽仅次于桌面档的最小一档，搜索占位读不全，
 * 顶栏铃铛在窄档隐藏——消息入口在管理端二级导航与用户菜单里仍在
 *（US-062 AC 8：收窄搜索框或在该档隐藏铃铛，非管理员本就看不到铃铛）。 */
@media (min-width: 640px) and (max-width: 719px) {
  .app-bell {
    display: none;
  }
}

/* --- 管理端外壳（US-086）---
 * 三档布局：≥1024px 常驻左侧栏、640–1023px 汉堡展开为行内面板、≤639px 为左侧
 * 抽屉（带遮罩）。开合状态由 `admin-nav.js` 维护在外壳的 `is-open` 类上，布局判断
 * 全部留在 CSS 里。任何一档都不产生横向滚动：抽屉用 `position: fixed` 浮在内容之上。 */

.admin-shell__bar {
  display: flex;
  margin-bottom: var(--space-4);
}

.admin-sidebar {
  display: none;
  margin-bottom: var(--space-4);
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.admin-shell.is-open .admin-sidebar {
  display: block;
}

.admin-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: var(--space-3);
}

.admin-sidebar__title {
  margin: 0;
  color: var(--ink-500);
  font-size: var(--text-small);
  font-weight: 600;
  letter-spacing: normal;
}

.admin-sidebar__close {
  display: none;
}

.admin-shell.is-open .admin-sidebar__close {
  display: inline-flex;
}

.admin-nav ul {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: var(--space-1) 0 0;
  padding: 0;
  list-style: none;
}

.admin-nav li {
  margin: 0;
}

.admin-nav a {
  display: flex;
  align-items: center;
  min-height: var(--tap-target);
  padding: var(--space-1) var(--space-3);
  color: var(--ink-700);
  font-size: var(--text-summary);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: background var(--duration-fast) var(--easing-standard);
}

.admin-nav a:hover {
  background: var(--brand-100);
  color: var(--brand-700);
}

.admin-nav a[aria-current="page"] {
  color: var(--brand-700);
  font-weight: 600;
  background: var(--brand-100);
}

.admin-nav :focus-visible {
  outline: 2px solid var(--brand-600);
  outline-offset: 2px;
}

/* 抽屉遮罩：只在 ≤639px 且展开时出现，点击可收起（脚本负责） */
.admin-shell__scrim {
  display: none;
}

@media (max-width: 639px) {
  .admin-shell.is-open .admin-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: min(280px, calc(100vw - var(--space-7)));
    padding: var(--space-3);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
    overflow-y: auto;
    margin-bottom: 0;
    border-radius: 0;
    box-shadow: var(--shadow-md);
  }

  .admin-shell.is-open .admin-shell__scrim {
    position: fixed;
    inset: 0;
    z-index: 25;
    display: block;
    background: var(--overlay-scrim);
  }
}

/* 桌面：常驻侧栏，汉堡与关闭按钮都不再需要 */
@media (min-width: 1024px) {
  .admin-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: var(--space-5);
    align-items: start;
  }

  .admin-shell__bar,
  .admin-shell__scrim {
    display: none;
  }

  /* 常驻侧栏不需要关闭按钮：这里用同等特异性的双类选择器盖掉展开态那条规则 */
  .admin-shell.is-open .admin-sidebar__close,
  .admin-sidebar__close {
    display: none;
  }

  .admin-sidebar {
    display: block;
    position: sticky;
    top: calc(64px + var(--space-4));
    margin-bottom: 0;
  }

  .admin-shell__content {
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-nav a,
  .app-icon-button,
  .admin-nav a,
  .skip-link {
    transition: none;
  }
}
