/* =========================================================================
 * 栗刻达 · 小程序端网页版 —— 外壳样式
 * 规则：这里只用「元素选择器 + .wx-* 类 + #id」，
 *      绝不使用高优先级的 id+元素 组合去抢小程序页面样式的活，
 *      保证 1:1 的页面样式始终由小程序 wxss 编译结果说了算。
 * ======================================================================= */

:root {
  --rpx: 0.5px;                 /* 750rpx = 375px（桌面端锁死） */
  --wx-vh: 100vh;
  --stage-bg: #eaeef7;
}
@media (max-width: 430px) {
  :root { --rpx: calc(100vw / 750); }
}

* { -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--stage-bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  color: #0f172a;
  overflow: hidden;
}

/* ---------- 舞台与手机壳 ---------- */
#wx-stage {
  min-height: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px 0; box-sizing: border-box;
  background:
    radial-gradient(1200px 600px at 50% -10%, #dfe6ff 0%, rgba(223,230,255,0) 60%),
    var(--stage-bg);
}
.wx-stage-brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: #64748b; letter-spacing: .3px;
}
.wx-stage-brand img { width: 22px; height: 22px; border-radius: 6px; }
#wx-app {
  width: 375px;
  height: min(820px, calc(100vh - 130px));
  background: #f6f7fb;
  border-radius: 26px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .18), 0 2px 0 rgba(255, 255, 255, .6) inset;
  display: flex; flex-direction: column;
  position: relative;
  transform: translateZ(0);      /* 让内部 position:fixed 元素以本容器为定位基准 */
  isolation: isolate;
}
@media (max-width: 430px) {
  #wx-app { width: 100vw; height: 100dvh; border-radius: 0; box-shadow: none; }
  #wx-stage { padding: 0; gap: 0; }
  .wx-stage-brand { display: none; }
}

/* ---------- 导航栏 ---------- */
#wx-navbar {
  flex: 0 0 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  position: relative; z-index: 5;
  background: #5b5bd6; color: #fff;
  font-size: 17px; font-weight: 600; letter-spacing: .3px;
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(44px + env(safe-area-inset-top, 0px));
  flex-basis: calc(44px + env(safe-area-inset-top, 0px));
}
.wx-nav-title { max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wx-nav-back {
  position: absolute; left: 6px; top: env(safe-area-inset-top, 0px); width: 40px; height: 44px;
  border: none; background: transparent; color: inherit;
  font-size: 26px; line-height: 1; cursor: pointer; opacity: .95;
}
.wx-nav-refresh {
  position: absolute; right: 8px; top: env(safe-area-inset-top, 0px); width: 40px; height: 44px;
  border: none; background: transparent; color: inherit; font-size: 18px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
}

/* ---------- 页面容器 ---------- */
#wx-body { flex: 1 1 auto; position: relative; overflow: hidden; background: #f6f7fb; }
.wx-page-root {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: #f6f7fb;
}
.wx-page-root::-webkit-scrollbar, .wx-scroll::-webkit-scrollbar,
#wx-body::-webkit-scrollbar, .wx-picker-list::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- 标签栏 ---------- */
#wx-tabbar {
  flex: 0 0 52px; height: 52px; display: none;
  align-items: stretch;
  border-top: 1px solid #e8ecf3;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: content-box;
  z-index: 4;
}
.wx-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  border: none; background: transparent; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 500;
  position: relative; padding: 0;
}
.wx-tab-ico { width: 22px; height: 22px; display: block; }
.wx-tab-text { font-size: 11px; line-height: 1.2; }
.wx-tab-badge {
  position: absolute; top: 8px; margin-left: 22px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: #ef4444; color: #fff; font-size: 11px; line-height: 16px; text-align: center;
}

/* =========================================================================
 * 小程序基础组件的等价渲染（默认样式对齐微信）
 * ======================================================================= */
button {
  font-family: inherit; font-size: inherit; color: inherit; line-height: 1.5;
  margin: 0; padding: 0; border: none; background: transparent;
  display: block; text-align: center; white-space: nowrap; box-sizing: border-box;
  cursor: pointer;
}
button:disabled { cursor: default; }
input, textarea {
  font-family: inherit; font-size: inherit; color: inherit;
  border: none; background: transparent; outline: none;
  box-sizing: border-box; margin: 0; width: 100%;
}
textarea { resize: none; }
img { vertical-align: top; max-width: none; }

.wx-block, .wx-comp-host { display: contents; }

/* switch（微信开关） */
.wx-switch {
  display: inline-block; width: 51px; height: 31px; border-radius: 16px;
  background: #e5e5e5; position: relative; flex: 0 0 auto;
  transition: background .2s ease; vertical-align: middle; cursor: pointer;
}
.wx-switch > .wx-switch-knob,
.wx-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: left .2s ease;
}
.wx-switch.on { background: var(--sw, #5b5bd6); }
.wx-switch.on::after { left: 22px; }

/* checkbox（微信勾选框） */
.wx-checkbox { width: 22px; height: 22px; flex: 0 0 auto; margin: 0; }

/* picker / swiper / scroll-view 容器 */
.wx-picker { display: block; cursor: pointer; }
.wx-swiper { scrollbar-width: none; }
.wx-swiper::-webkit-scrollbar { height: 0; }
.wx-swiper-item { min-width: 100%; }

/* 下拉刷新指示器 */
.wx-pulldown {
  height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center;
  gap: 8px; font-size: 12px; color: #94a3b8;
  transition: height .2s ease; position: relative; z-index: 1;
}
.wx-pulldown-spin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #c7d2fe; border-top-color: #5b5bd6; display: inline-block;
}
.wx-pulldown.loading .wx-pulldown-spin { animation: wx-spin .8s linear infinite; }
@keyframes wx-spin { to { transform: rotate(360deg); } }

/* =========================================================================
 * 交互反馈（toast / modal / loading / sheet / 图片预览）
 * ======================================================================= */
#wx-overlays { position: fixed; inset: 0; pointer-events: none; z-index: 9999; }
#wx-overlays > * { pointer-events: auto; }

.wx-toast {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.94);
  opacity: 0; transition: opacity .18s ease, transform .18s ease;
  background: rgba(17, 24, 39, .82); color: #fff; border-radius: 12px;
  padding: 18px 20px; max-width: 70%; text-align: center;
}
.wx-toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.wx-toast-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.wx-toast-icon {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .85);
  display: flex; align-items: center; justify-content: center; font-size: 20px; line-height: 1;
}
.wx-toast-icon.loading { border-color: rgba(255,255,255,.35); border-top-color: #fff; animation: wx-spin .8s linear infinite; }
.wx-toast-text { font-size: 14px; line-height: 1.4; white-space: pre-wrap; }

.wx-loading-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .12);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .18s ease;
}
.wx-loading-mask.show { opacity: 1; }
.wx-loading-box {
  min-width: 120px; padding: 20px 16px; border-radius: 12px;
  background: rgba(17, 24, 39, .82); color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.wx-spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .3); border-top-color: #fff;
  animation: wx-spin .8s linear infinite;
}
.wx-loading-text { font-size: 13px; }

.wx-modal-mask, .wx-sheet-mask, .wx-preview-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .18s ease;
}
.wx-modal-mask.show, .wx-sheet-mask.show, .wx-preview-mask.show { opacity: 1; }
.wx-modal {
  width: 280px; background: #fff; border-radius: 14px; overflow: hidden;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
  transform: translateY(6px); transition: transform .18s ease;
}
.wx-modal-mask.show .wx-modal { transform: translateY(0); }
.wx-modal-title { padding: 22px 20px 0; font-size: 16px; font-weight: 600; text-align: center; }
.wx-modal-content {
  padding: 12px 20px 20px; font-size: 14px; color: #475569; text-align: center;
  white-space: pre-wrap; max-height: 46vh; overflow-y: auto; line-height: 1.6;
}
.wx-modal-foot { display: flex; border-top: 1px solid #eef2f7; }
.wx-modal-btn {
  flex: 1; height: 48px; font-size: 16px; color: #334155; background: #fff;
}
.wx-modal-btn + .wx-modal-btn { border-left: 1px solid #eef2f7; }
.wx-modal-btn.primary { color: #5b5bd6; font-weight: 600; }

.wx-sheet-mask { align-items: flex-end; }
.wx-sheet {
  width: 100%; max-height: 70%; background: #f6f7fb;
  border-radius: 16px 16px 0 0; overflow-y: auto;
  transform: translateY(20px); transition: transform .22s ease;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.wx-sheet-mask.show .wx-sheet { transform: translateY(0); }
.wx-sheet-item {
  width: 100%; height: 52px; background: #fff; font-size: 16px; color: #0f172a;
  border-bottom: 1px solid #f1f5f9;
}
.wx-sheet-item.cancel { margin-top: 8px; border-bottom: none; color: #64748b; }
.wx-picker-list { background: #fff; }
.wx-picker-item {
  width: 100%; height: 48px; background: #fff; font-size: 15px; color: #334155;
  border-bottom: 1px solid #f8fafc;
}
.wx-picker-item.on { color: #5b5bd6; font-weight: 600; }

.wx-preview-mask { background: rgba(0, 0, 0, .92); }
.wx-preview-img { max-width: 92%; max-height: 78%; object-fit: contain; }
.wx-preview-tip {
  position: absolute; bottom: 26px; left: 0; right: 0; text-align: center;
  color: rgba(255, 255, 255, .8); font-size: 13px;
}
.wx-preview-close {
  position: absolute; top: 16px; right: 18px; color: #fff; font-size: 20px;
  width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, .16);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
