/* ===== 统一页面壳层 — 仅在 ≥768px 启用布局 ===== */

/* ── 根容器 ── */
.pg-layout {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
}

.pg-layout-simple {
  grid-template-columns: 1fr;
}

.pg-layout:not(.pg-layout-simple) {
  grid-template-columns: var(--sidebar-width, 220px) minmax(0, 1fr);
}

.shell-auth-anonymous .pg-layout:not(.pg-layout-simple) {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.shell-auth-anonymous .page-topbar {
  display: none;
}

.shell-auth-anonymous .page-sidebar {
  display: none;
}

.shell-auth-anonymous .pg-main {
  grid-column: 1 / -1;
  min-height: 100vh;
}

/* ── 顶栏 ── */
.page-topbar {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-height, 54px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-md, 16px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.page-topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm, 10px);
  min-width: 0;
}

.page-topbar-logo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 62px;
  height: 38px;
  overflow: hidden;
  text-decoration: none;
}

.page-topbar-logo-link .aca-logo-badge.is-portal {
  margin: 0;
}

.page-topbar-copy {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm, 10px);
  min-width: 0;
}

.page-topbar-title {
  margin: 0;
  font-size: var(--text-section-title, 0.96rem);
  font-weight: var(--weight-title, 720);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-topbar-copy .page-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-aux, 0.82rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs, 6px);
  flex-shrink: 0;
}

.page-primary-action {
  white-space: nowrap;
}

.shell-action-menu {
  display: contents;
}

.shell-action-menu-toggle {
  display: none;
}

.shell-action-menu-list {
  display: flex;
  align-items: center;
  gap: var(--space-xs, 6px);
}

.page-topbar-user {
  display: grid;
  gap: 2px;
  min-width: 0;
  max-width: 260px;
  text-align: right;
}

.page-topbar-user.is-muted {
  color: var(--text-muted);
  font-size: var(--text-aux, 0.82rem);
}

.page-topbar-user-name {
  overflow: hidden;
  color: var(--text);
  font-size: var(--text-body, 0.9rem);
  font-weight: var(--weight-section, 700);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-topbar-user-meta {
  overflow: hidden;
  color: var(--text-muted);
  font-size: var(--text-aux, 0.82rem);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 侧边栏 ── */
.page-sidebar {
  position: sticky;
  top: var(--topbar-height, 54px);
  height: calc(100vh - var(--topbar-height, 54px));
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: var(--space-xs, 6px) 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.page-nav-section-label {
  padding: var(--space-md, 16px) var(--space-md, 16px) 4px;
  color: var(--text-subtle, var(--text-muted));
  font-size: 0.66rem;
  font-weight: var(--weight-section, 700);
  letter-spacing: 0;
}

.page-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-xs, 6px);
  min-height: 38px;
  padding: 8px var(--space-md, 16px);
  margin: 0 var(--space-xs, 6px);
  border-radius: var(--radius-sm, 8px);
  color: var(--text);
  font-size: var(--text-aux, 0.88rem);
  font-weight: var(--weight-section, 700);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  cursor: pointer;
}

.page-nav-item:hover {
  background: rgba(26, 110, 245, 0.07);
}

.page-nav-item.active {
  background: rgba(26, 110, 245, 0.1);
  color: var(--accent-strong);
  font-weight: var(--weight-section, 700);
}

.page-nav-item.active::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 999px;
  background: var(--brand);
}

/* ── 主内容区 ── */
.pg-main {
  min-width: 0;
  padding: var(--space-lg, 24px) var(--space-lg, 24px) 40px;
  overflow-y: auto;
}

.has-page-sidebar .pg-main .knowledge-shell,
.has-page-sidebar .pg-main .assistant-shell,
.has-page-sidebar .pg-main .app-shell {
  max-width: min(1180px, 100%);
  margin: 0;
  padding: 0;
}

.has-page-sidebar .pg-main > .assistant-bg,
.has-page-sidebar .pg-main > .bg-layer {
  display: none;
}

.has-page-shell .back-link {
  display: none;
}

/* 桌面壳层内不再需要旧居中容器限制 */
.pg-main .app-shell,
.pg-main .wrap,
.pg-main .shell {
  max-width: none;
  margin: 0;
  padding: 0;
  gap: var(--space-md, 16px);
}

.pg-main .app-shell .bg-layer,
.pg-main .wrap .bg-layer,
.pg-main .shell .bg-layer {
  display: none;
}

/* 壳层内的内容页保留内部间距 */
.pg-main .wrap.app-wrap {
  padding: 0;
  max-width: none;
}

/* ===== 平板（768-1023px）侧边栏收窄 ===== */
@media (min-width: 768px) and (max-width: 1023px) {
  .pg-layout:not(.pg-layout-simple) {
    grid-template-columns: var(--sidebar-width-collapsed, 50px) minmax(0, 1fr);
  }

  .page-sidebar {
    top: var(--topbar-height, 54px);
    height: calc(100vh - var(--topbar-height, 54px));
    padding: var(--space-xs, 6px) 0;
  }

  .page-nav-section-label { display: none; }
  .page-nav-item { justify-content: center; padding: var(--space-sm, 10px) 0; margin: 0 var(--space-xs, 6px); }
  .nav-label { display: none; }

  .pg-main { padding: var(--space-md, 16px) 14px var(--space-xl, 32px); }
}

/* ===== 手机（<768px）壳层恢复为移动布局 ===== */
@media (max-width: 767px) {
  .pg-layout,
  .pg-layout:not(.pg-layout-simple) {
    grid-template-columns: 1fr;
    display: block;
  }

  .page-topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-height, 54px);
    flex-direction: row;
    align-items: center;
    padding: 0 12px;
    gap: var(--space-xs, 6px);
    background: rgba(255, 255, 255, 0.93);
  }

  .page-topbar-brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  .page-topbar-actions {
    width: auto;
    max-width: 58vw;
    margin-left: auto;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow: visible;
  }

  .page-primary-action {
    max-width: calc(58vw - 52px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .page-topbar-user {
    display: none;
  }

  .page-topbar-copy .page-sub {
    display: none;
  }

  .page-sidebar {
    display: none;
  }

  .shell-action-menu {
    position: relative;
    display: block;
  }

  .shell-action-menu-toggle {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    white-space: nowrap;
  }

  .shell-action-menu-list {
    position: absolute;
    top: calc(100% + var(--space-xs, 8px));
    right: 0;
    z-index: 140;
    display: none;
    min-width: 168px;
    padding: var(--space-xs, 8px);
    border: 1px solid var(--line);
    border-radius: var(--radius-md, 12px);
    background: var(--surface-solid, #fff);
    box-shadow: var(--shadow-lg);
  }

  .shell-action-menu.is-open .shell-action-menu-list {
    display: grid;
    gap: var(--space-xs, 8px);
  }

  .shell-action-menu-list .btn {
    width: 100%;
    justify-content: center;
    white-space: nowrap;
  }

  .pg-main {
    padding: 0;
  }

  /* 移动端恢复原有容器 */
  .pg-main .wrap {
    max-width: 920px;
    margin: 0 auto;
    padding: var(--space-lg, 24px) 14px var(--space-xl, 32px);
    gap: 14px;
  }

  .pg-main .app-shell {
    max-width: 1340px;
    margin: 0 auto;
    padding: 24px 16px 32px;
  }
}

/* ===== 小屏手机 ===== */
@media (max-width: 480px) {
  .page-topbar {
    padding: 10px 10px;
  }

  .page-topbar-brand {
    gap: 8px;
  }

  .page-topbar-title {
    font-size: 0.88rem;
  }
}
