/* ============================================================================
   骨架层：顶栏 / 侧边栏 / 内容区 / 页脚 + 响应式
   结构参照参考后台：顶部品牌栏 + 左侧树形菜单 + 右侧内容 + 页脚
   视觉参照 qrbjx.com：白底半透明模糊导航、主色浅底选中态
   ========================================================================== */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* -------------------------------- 顶栏 -------------------------------- */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-header);
}

/* 汉堡按钮：仅移动端显示 */
.header-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  padding: 6px;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  flex: none;
}

.header-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--text-dark);
  border-radius: 2px;
  transition: var(--tr-fast);
}

.header-toggle.is-active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.header-toggle.is-active span:nth-child(2) { opacity: 0; }
.header-toggle.is-active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.app-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--text-dark);
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex: none;
}

.app-brand:hover {
  color: var(--text-dark);
}

.app-brand .logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--geo));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 3px 10px rgba(37, 99, 235, .32);
  flex: none;
}

.app-brand .accent {
  color: var(--primary);
}

.header-spacer {
  flex: 1;
}

/* 顶栏右侧：余额 + 用户菜单 */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.balance-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  background: rgba(37, 99, 235, .07);
  border: 1px solid rgba(37, 99, 235, .16);
  font-size: var(--fs-sm);
  color: var(--primary-dark);
  font-weight: 600;
  white-space: nowrap;
}

.balance-chip .amount {
  font-variant-numeric: tabular-nums;
}

.user-menu {
  position: relative;
}

.user-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1.5px solid transparent;
  border-radius: 20px;
  background: transparent;
  transition: var(--tr-fast);
  color: var(--text-mid);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.user-trigger:hover,
.user-menu.is-open .user-trigger {
  background: var(--bg-tint);
  border-color: rgba(37, 99, 235, .16);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-light), var(--geo));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-sm);
  font-weight: 700;
  flex: none;
}

.avatar-lg {
  width: 46px;
  height: 46px;
  font-size: var(--fs-lg);
}

.user-trigger .caret {
  width: 10px;
  height: 10px;
  transition: transform .22s;
  color: var(--text-light);
}

.user-menu.is-open .user-trigger .caret {
  transform: rotate(180deg);
}

/* 下拉菜单 */
.dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xl);
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity .2s ease, visibility .2s ease, transform .2s ease;
  z-index: 10;
}

.user-menu.is-open .dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 6px;
}

.dropdown-header .name {
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.3;
}

.dropdown-header .sub {
  font-size: var(--fs-xs);
  color: var(--text-light);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  color: var(--text-mid);
  text-align: left;
  transition: var(--tr-fast);
}

.dropdown-item:hover {
  background: var(--bg-tint);
  color: var(--primary);
}

.dropdown-item.is-danger:hover {
  background: #fef2f2;
  color: var(--danger-dark);
}

.dropdown-item svg {
  flex: none;
  color: currentColor;
  opacity: .8;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-light);
  margin: 6px 0;
}

/* ------------------------------- 侧边栏 ------------------------------- */

.app-sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: var(--z-sidebar);
  transition: transform .28s cubic-bezier(.2, .8, .3, 1);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-user .name {
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.3;
  word-break: break-all;
}

.sidebar-user .role {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  color: var(--text-light);
  margin-top: 2px;
}

.sidebar-user .role::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .15);
}

.nav-section {
  padding: 14px 12px 6px;
}

.nav-label {
  padding: 0 10px 8px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .06em;
}

.nav-item {
  margin-bottom: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-mid);
  text-align: left;
  transition: var(--tr-fast);
  position: relative;
}

.nav-link:hover {
  background: var(--bg-tint);
  color: var(--primary);
}

.nav-link .nav-icon {
  flex: none;
  width: 17px;
  height: 17px;
  color: currentColor;
  opacity: .85;
}

.nav-link .nav-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-link .nav-arrow {
  flex: none;
  width: 11px;
  height: 11px;
  color: var(--text-muted);
  transition: transform .22s;
}

.nav-item.is-open > .nav-link .nav-arrow {
  transform: rotate(90deg);
}

/* 子菜单 */
.nav-sub {
  display: none;
  padding: 3px 0 4px 0;
}

.nav-item.is-open > .nav-sub {
  display: block;
}

.nav-sub .nav-link {
  padding-left: 36px;
  font-size: var(--fs-sm);
  color: var(--text-light);
}

.nav-sub .nav-link::before {
  content: "";
  position: absolute;
  left: 21px;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--border-strong);
  transform: translateY(-50%);
  transition: var(--tr-fast);
}

.nav-sub .nav-link:hover::before {
  background: var(--primary);
}

/* 当前页高亮：浅主色底 + 左侧主色条（对应 qrbjx 的 .nav-link.active 语言） */
.nav-sub .nav-link.is-active,
.nav-link.is-active {
  background: var(--bg-tint);
  color: var(--primary);
  font-weight: 600;
}

.nav-sub .nav-link.is-active::before {
  background: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .18);
}

.nav-sub .nav-link.is-active::after {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--primary);
}

/* 侧边栏底部客服 */
.sidebar-footer {
  margin-top: 10px;
  padding: 16px 14px 24px;
  border-top: 1px solid var(--border-light);
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  font-size: var(--fs-sm);
  color: var(--text-light);
}

.contact-item .k {
  flex: none;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-hover);
  font-size: var(--fs-xs);
  color: var(--text-mid);
}

/* 移动端遮罩 */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0 0;
  background: rgba(15, 23, 42, .4);
  z-index: calc(var(--z-sidebar) - 1);
  animation: fadeIn .2s ease;
}

/* ------------------------------- 内容区 ------------------------------- */

.app-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
  padding: var(--gap);
  min-width: 0;
}

.app-main-inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* 面包屑 + 页标题 */
.page-head {
  margin-bottom: 16px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  color: var(--text-light);
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.breadcrumb .sep {
  color: var(--border-strong);
}

.breadcrumb .current {
  color: var(--text-mid);
  font-weight: 500;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.page-title h1 {
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--text-dark);
  letter-spacing: -0.02em;
}

.page-title .sub {
  font-size: var(--fs-sm);
  color: var(--text-light);
  padding-top: 4px;
}

.page-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

/* -------------------------------- 页脚 -------------------------------- */

.app-footer {
  margin-left: var(--sidebar-w);
  padding: 16px var(--gap) 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  flex-wrap: wrap;
}

.app-footer a {
  color: var(--text-light);
  font-weight: 600;
}

.app-footer a:hover {
  color: var(--primary);
}

/* ============================================================================
   响应式
   ========================================================================== */

/* 1300px 以下：内容区留白收紧 */
@media (max-width: 1300px) {
  :root {
    --gap: 16px;
  }
}

/* 1024px 以下：侧边栏转为抽屉 */
@media (max-width: 1024px) {
  .header-toggle {
    display: flex;
  }

  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }

  body.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  body.sidebar-open .sidebar-overlay {
    display: block;
  }

  .app-main,
  .app-footer {
    margin-left: 0;
  }

  .app-main {
    padding: 14px;
  }

  .app-header {
    padding: 0 14px;
    gap: 10px;
  }
}

/* 768px 以下：顶栏信息精简，标题区上下堆叠 */
@media (max-width: 768px) {
  :root {
    --header-h: 56px;
    --gap: 12px;
  }

  .app-brand {
    font-size: var(--fs-md);
  }

  .balance-chip {
    display: none;
  }

  .user-trigger .user-name {
    display: none;
  }

  .page-title h1 {
    font-size: var(--fs-lg);
  }

  .page-title .sub {
    width: 100%;
    padding-top: 0;
  }

  .page-actions {
    margin-left: 0;
    width: 100%;
  }

  .page-actions .btn {
    flex: 1;
  }

  .app-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .card-body {
    padding: 16px;
  }

  .card-head {
    padding: 14px 16px;
  }
}

/* 480px 以下：更紧凑 */
@media (max-width: 480px) {
  .app-main {
    padding: 10px;
  }

  .filter-bar {
    gap: 8px;
  }

  /* 移动端筛选项两列布局，比整行堆叠紧凑，又不会挤成一团 */
  .filter-bar .input,
  .filter-bar .select,
  .filter-bar .input[type="text"],
  .filter-bar .input[type="date"] {
    width: calc(50% - 4px);
    min-width: 0;
    flex: 0 0 calc(50% - 4px);
  }

  /* 长文本筛选独占一行（由 data-wide 显式标记，不靠结构猜） */
  .filter-bar [data-wide] {
    width: 100%;
    flex-basis: 100%;
  }

  .filter-actions {
    margin-left: 0;
    width: 100%;
  }

  .filter-actions .btn {
    flex: 1;
  }

  /* 搜索/重置并排，各占一半 */
  .filter-bar .btn {
    flex: 1 1 calc(50% - 4px);
  }

  .breadcrumb {
    font-size: var(--fs-xs);
  }
}
