/* V2 application shell. Page-specific styles remain in the existing bundles. */
:root {
  --shell-topbar: 64px;
  --shell-sidebar: 248px;
  --shell-sidebar-collapsed: 72px;
  --shell-border: #dfe6ee;
  --shell-bg: #f4f7fa;
}

html,
body {
  min-width: 0;
}

.sidebar[hidden] {
  display: none !important;
}

/* 模块分组整体（标题 + 菜单）显隐；.nav 是 flex，不能被单独的 hidden 覆盖。 */
.module-sidebar .nav-group[hidden] {
  display: none !important;
}

body.module-body {
  min-height: 100vh;
  padding-top: var(--shell-topbar);
  overflow-x: hidden;
  background: var(--shell-bg);
}

.skip-link {
  position: fixed;
  left: 16px;
  top: -48px;
  z-index: 200;
  padding: 9px 12px;
  border-radius: 6px;
  background: #061f32;
  color: #fff;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.topnav {
  position: fixed !important;
  top: 0 !important;
  right: 0;
  left: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  min-height: var(--shell-topbar);
  padding: 0 24px;
  gap: 24px;
  border-bottom: 1px solid var(--shell-border);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 1px 8px rgba(6, 31, 50, .04);
}

.topnav-left,
.topnav-right,
.topnav-tabs,
.user,
.global-search {
  display: flex;
  align-items: center;
}

.topnav-left,
.topnav-right {
  gap: 12px;
}

.topnav-left {
  flex: 0 0 auto;
}

.topnav-tabs {
  align-self: stretch;
  gap: 4px;
  min-width: 0;
}

.topnav-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: var(--shell-topbar);
  padding: 0 14px;
  color: #5a6b7c;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.topnav-tab:hover,
.topnav-tab.active {
  color: #0b63ce;
}

.topnav-tab.active::after {
  position: absolute;
  right: 12px;
  bottom: -1px;
  left: 12px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: #0b63ce;
  content: "";
}

/* 窄屏一级导航放不下时横向滚动：JS 给 .topnav-tabs 加 is-scrollable / is-at-start / is-at-end，
   两端渐隐提示还有未显示的 Tab。 */
.topnav-tabs.is-scrollable {
  --tabs-fade-l: 0px;
  --tabs-fade-r: 0px;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 var(--tabs-fade-l), #000 calc(100% - var(--tabs-fade-r)), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 var(--tabs-fade-l), #000 calc(100% - var(--tabs-fade-r)), transparent 100%);
}

.topnav-tabs.is-scrollable:not(.is-at-start) {
  --tabs-fade-l: 18px;
}

.topnav-tabs.is-scrollable:not(.is-at-end) {
  --tabs-fade-r: 18px;
}

.topnav-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #061f32;
  text-decoration: none;
  white-space: nowrap;
}

.topnav-brand .brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #08a6f6, #0b63ce);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.topnav-brand .brand-name {
  color: #061f32;
  font-size: 13px;
  font-weight: 750;
}

.menu-btn,
.collapse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #5a6b7c;
  cursor: pointer;
}

/* 桌面侧栏常驻，无需汉堡入口；仅移动端抽屉显示（见 @media max-width:760px）。 */
.menu-btn {
  display: none;
}

.menu-btn:hover,
.collapse-btn:hover {
  background: #f4f7fa;
  color: #0b63ce;
}

.topnav-right {
  flex: 1 1 auto;
  justify-content: flex-end;
  min-width: 0;
}

.global-search {
  /* 页面级样式（如旧版页面的 label{margin-bottom:4px}）会漏到顶栏搜索框，这里锁死。 */
  margin: 0;
  width: min(280px, 24vw);
  height: 36px;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--shell-border);
  border-radius: 7px;
  background: #f7f9fb;
}

.global-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #1a2b3c;
  font: inherit;
  font-size: 12px;
}

.search-icon {
  flex: 0 0 auto;
  color: #93a2b2;
}

.user {
  gap: 9px;
  min-width: 0;
  padding-left: 12px;
  border-left: 1px solid var(--shell-border);
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(135deg, #0b63ce, #08a6f6);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.user-info {
  min-width: 0;
  line-height: 1.35;
}

.user-name {
  overflow: hidden;
  color: #1a2b3c;
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  overflow: hidden;
  color: #93a2b2;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shell {
  position: relative;
  display: flex;
  min-height: calc(100vh - var(--shell-topbar));
}

.module-sidebar {
  position: fixed;
  top: var(--shell-topbar);
  bottom: 0;
  left: 0;
  z-index: 70;
  width: var(--shell-sidebar);
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid rgba(255, 255, 255, .08);
  background: linear-gradient(180deg, #061f32 0%, #082741 100%);
  transition: width .2s ease, transform .2s ease;
}

.module-sidebar.collapsed {
  width: var(--shell-sidebar-collapsed);
}

.module-sidebar.collapsed .sidebar-title,
.module-sidebar.collapsed .nav-text,
.module-sidebar.collapsed .sidebar-footer {
  display: none;
}

.module-sidebar.collapsed .sidebar-head {
  justify-content: center;
  padding-inline: 0;
}

.module-sidebar.collapsed .nav-item {
  justify-content: center;
  padding-inline: 12px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 16px 0 20px;
  border-bottom: 1px solid rgba(255, 255, 255, .09);
}

.sidebar-title {
  overflow: hidden;
  color: #d6e6f5;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.module-sidebar .collapse-btn {
  color: #9dbbd3;
}

.module-sidebar .collapse-btn:hover {
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

.module-sidebar .nav {
  gap: 2px;
  padding: 10px 10px 10px;
}

.module-sidebar .nav-item {
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 7px;
  color: #b3c9dc;
  font-size: 13px;
  text-decoration: none;
}

.module-sidebar .nav-item:hover {
  background: rgba(255, 255, 255, .07);
  color: #fff;
}

.module-sidebar .nav-item.active {
  background: rgba(8, 166, 246, .16);
  color: #fff;
  font-weight: 700;
}

.module-sidebar .nav-item.active::before {
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: #08a6f6;
}

.module-sidebar .nav-icon {
  width: 22px;
  color: #79add2;
}

.module-sidebar .nav-item.active .nav-icon {
  color: #5cc8ff;
}

.module-sidebar .sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, .09);
}

.shell-main {
  width: calc(100% - var(--shell-sidebar));
  min-width: 0;
  margin-left: var(--shell-sidebar);
  transition: width .2s ease, margin-left .2s ease;
}

.shell.is-collapsed .shell-main {
  width: calc(100% - var(--shell-sidebar-collapsed));
  margin-left: var(--shell-sidebar-collapsed);
}

.shell.demo-home .shell-main,
.shell.demo-home {
  width: 100%;
  margin-left: 0;
}

.demo-sidebar.is-hidden {
  display: none;
}

.page-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  gap: 16px;
  padding: 12px 28px 0;
}

.page-bar .breadcrumb {
  min-width: 0;
  color: #93a2b2;
  font-size: 12px;
}

.page-bar .breadcrumb a {
  color: #5a6b7c;
  text-decoration: none;
}

.page-bar .breadcrumb a:hover {
  color: #0b63ce;
}

.page-bar .breadcrumb .sep {
  padding: 0 3px;
  color: #c7d2dc;
}

.page-bar .breadcrumb [aria-current="location"] {
  overflow: hidden;
  color: #1a2b3c;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 24px 28px 40px;
}

.demo-content,
.demo-pages,
.demo-content .page,
.demo-content .page-head,
.demo-content .selection-layout,
.demo-content .selection-layout > *,
.demo-content .card {
  min-width: 0;
  max-width: 100%;
}

.demo-content input,
.demo-content select,
.demo-content textarea {
  max-width: 100%;
}

.home-content {
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}

.sidebar-backdrop {
  display: none;
}

.module-body :is(a, button, input, select, textarea):focus-visible {
  outline: 3px solid rgba(8, 166, 246, .42);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .topnav {
    gap: 12px;
    padding-inline: 16px;
  }

  .topnav-brand .brand-name,
  .user-info {
    display: none;
  }

  .topnav-tabs {
    flex: 1 1 auto;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .topnav-tabs::-webkit-scrollbar {
    display: none;
  }

  .topnav-tab {
    padding-inline: 10px;
  }

  .global-search {
    display: none;
  }
}

/* 平板宽度：侧栏仍占 248px，选号页若保持 340px 表单 + 结果双列，结果卡会被压到约 100px。
   此区间先堆叠表单与结果，>1100px 恢复桌面双列。 */
@media (max-width: 1100px) {
  .demo-content .selection-layout {
    display: block;
  }

  .demo-content .selection-layout .req-card {
    position: static;
  }
}

@media (max-width: 760px) {
  body.module-body {
    --shell-topbar: 60px;
  }

  .topnav {
    min-height: 60px;
  }

  .menu-btn {
    display: inline-flex;
  }

  .topnav-tab {
    min-height: 60px;
    font-size: 12px;
  }

  .module-sidebar {
    top: var(--shell-topbar);
    width: min(86vw, 300px);
    transform: translateX(-102%);
    box-shadow: 12px 0 28px rgba(6, 31, 50, .18);
  }

  .module-sidebar.is-open {
    transform: translateX(0);
  }

  .shell-main,
  .shell.is-collapsed .shell-main {
    width: 100%;
    margin-left: 0;
  }

  .shell.is-collapsed .module-sidebar {
    width: min(86vw, 300px);
  }

  .sidebar-backdrop.is-visible {
    position: fixed;
    inset: var(--shell-topbar) 0 0;
    z-index: 60;
    display: block;
    /* 旧样式表给 .sidebar-backdrop 设了 pointer-events:none / opacity:0（其 .show 类本壳不用），
       这里必须恢复，否则遮罩不可见、点遮罩也关不掉抽屉。 */
    pointer-events: auto;
    opacity: 1;
    background: rgba(6, 31, 50, .42);
  }

  .page-bar {
    min-height: 42px;
    padding: 10px 16px 0;
  }

  .content,
  .home-content {
    padding: 18px 16px 32px;
  }

  .demo-content .page-head > div {
    min-width: 0;
    max-width: 100%;
  }

  .demo-content .selection-layout {
    display: block;
    width: calc(100vw - 32px) !important;
    overflow: hidden;
  }

  .demo-content .selection-layout > .card {
    width: calc(100vw - 32px) !important;
  }

  .demo-content .weight-info {
    white-space: normal;
  }
}

/* 390 及更窄：四个一级模块 Tab 必须完整可点。收起纯展示的用户头像，压缩 Tab 内边距，
   四页 Tab（首页/采买执行/智能专家/数据中心）在 390 下完整排下；更窄时由 .topnav-tabs 横滑 + 渐隐提示兜底。 */
@media (max-width: 480px) {
  .topnav {
    gap: 6px;
    padding-inline: 10px;
  }

  .topnav-right .user {
    display: none;
  }

  .topnav-tabs {
    gap: 2px;
  }

  .topnav-tab {
    padding-inline: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .module-sidebar,
  .shell-main {
    transition: none;
  }
}
