/**
 * 小程序原型 - 布局：顶部栏、Tab、页面容器、二级页
 */

/**
 * PC 强制手机宽度；竖屏比例 9:16（高:宽 = 16:9），中间 .app-scroll 可滚动。
 * transform 使壳内 position:fixed（Toast、二级页等）相对手机框定位。
 */
#miniapp-shell {
  width: 100%;
  max-width: 430px;
  margin-left: auto;
  margin-right: auto;
  position: relative;
  transform: translateZ(0);
  background: var(--apple-bg);
  display: flex;
  flex-direction: column;
  aspect-ratio: 9 / 16;
  max-height: 100vh;
  max-height: min(100vh, 100dvh);
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  background: var(--apple-bg);
}

@media (min-width: 431px) {
  html {
    background: #2c2c2e;
  }
  #miniapp-shell {
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.08),
      0 24px 64px rgba(0, 0, 0, 0.35);
  }
}

/* 微信小程序风格 - 顶部状态栏 + 导航栏（随壳 flex 置顶，不占用滚动区） */
.wx-header {
  flex-shrink: 0;
  position: relative;
  z-index: 200;
  background: var(--apple-group);
  border-bottom: 0.5px solid var(--apple-separator);
  box-shadow: 0 1px 0 rgba(0,0,0,0.05);
}
.wx-status-bar {
  height: var(--wx-status-h); padding-top: var(--safe-top);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 22px; padding-right: 22px;
  font-size: 14px; font-weight: 500; color: var(--apple-label);
  background: var(--apple-group);
}
.wx-status-bar .status-time { letter-spacing: 0.5px; }
.wx-status-bar .status-icons { display: flex; align-items: center; gap: 4px; font-size: 14px; }
.wx-nav-bar {
  height: var(--wx-nav-h);
  display: flex; align-items: center; justify-content: center;
  position: relative; background: var(--apple-group);
}
.wx-nav-bar .wx-nav-title {
  font-size: 17px; font-weight: 600; color: var(--apple-label);
}
.wx-nav-bar .wx-nav-home {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-radius: 8px;
  transition: background 0.2s;
}
.wx-nav-bar .wx-nav-home:active { background: var(--apple-fill); }
.wx-nav-bar .wx-nav-capsule {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  width: 87px; height: 32px;
  background: rgba(0,0,0,0.05); border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--apple-label-secondary);
}

/* 底部 Tab - 毛玻璃风格（随壳 flex 置底） */
.tab-bar {
  flex-shrink: 0;
  position: relative;
  height: calc(var(--tab-h) + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--apple-separator);
  display: flex; justify-content: space-around; align-items: flex-start;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}
.tab-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: var(--tab-h); font-size: 10px; color: var(--apple-label-secondary);
  text-decoration: none; transition: color 0.2s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-item:active { transform: scale(0.96); }
.tab-item.active { color: var(--apple-blue); font-weight: 600; }
.tab-item .icon { font-size: 24px; margin-bottom: 2px; }

/* 主内容区：router 注入的页面容器（在 .app-scroll 内纵向滚动） */
.app-main {
  min-height: 100%;
  padding: 16px;
  box-sizing: border-box;
}

/* 页面容器（注入到 .app-main 内的片段使用） */
.page { min-height: 100%; }
.page.active { display: block; animation: pageIn 0.25s ease; }
@keyframes pageIn { from { opacity: 0.6; } to { opacity: 1; } }

/* hash 下钻页（如动态详情、发布页）的头部与内容区 */
.page .sub-header {
  display: flex;
  align-items: center;
  padding: 12px 12px;
  background: var(--apple-group);
  border-radius: var(--radius-lg);
  margin: -8px -8px 16px -8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  position: relative;
  min-height: 48px;
}
.page .sub-header .back {
  flex-shrink: 0;
  min-height: 44px;
  margin: -12px 0;
  padding-right: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  font-size: 20px;
  color: var(--apple-blue);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.page .sub-header .title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 100px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  color: var(--apple-label);
  pointer-events: none;
}
.page .sub-header .header-action {
  flex-shrink: 0;
  margin-left: auto;
  padding: 8px 4px;
  font-size: 18px;
  color: var(--apple-label);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.page .page-body {
  padding-bottom: 24px;
}

/* 二级页面：服务详情、支付、我的订单（盖满手机壳，高于顶栏 Tab） */
.sub-page {
  display: none;
  position: fixed; left: 0; right: 0; top: 0; bottom: 0;
  z-index: 300;
  background: var(--apple-bg);
  flex-direction: column;
  padding-top: var(--wx-header-h);
}
.sub-page.active { display: flex; animation: pageIn 0.25s ease; }
.sub-page .sub-header {
  position: fixed; left: 0; right: 0; top: 0;
  z-index: 151;
  height: var(--wx-header-h);
  background: var(--apple-group);
  border-bottom: 0.5px solid var(--apple-separator);
  display: flex;
  align-items: center;
  padding: 0 12px;
  padding-top: var(--safe-top);
}
.sub-page .sub-header .back {
  flex-shrink: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-right: 8px;
  font-size: 20px;
  color: var(--apple-blue);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.sub-page .sub-header .title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 100px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  color: var(--apple-label);
  pointer-events: none;
}
.sub-page .sub-header .header-action {
  flex-shrink: 0;
  margin-left: auto;
  padding: 8px 4px;
  font-size: 18px;
  color: var(--apple-label);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sub-page .sub-body {
  flex: 1; overflow-y: auto;
  padding: 16px; padding-bottom: 100px;
}
.sub-page .sub-footer {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--apple-group);
  border-top: 0.5px solid var(--apple-separator);
  z-index: 151;
}
