/* ═══════════════════════════════════════════════════
   M-Model V3 — Layout
   侧栏 · 主区域 · 底部栏 · Ticker
   ═══════════════════════════════════════════════════ */

/* v74(2026-07-10):page-header 高度变量,JS 实测写入(dashboard._renderHeader 测 offsetHeight)。
   不在 :root 定义 → content top 用 var(--header-h, 52px) fallback:首屏(JS 未跑)取 52px 估值避让 dashboard header;
   app.js 切非 dashboard 页设 0(content 顶到 ticker 下),dashboard._renderHeader 设实际 offsetHeight */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: 16px; /* body 用 px 固定基准，rem token 依赖此值 */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden; /* managed by layout */
}

/* ─── App Shell ─── */
.v3-app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ─── Sidebar (PC) ─── */
.v3-sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 2px;
  z-index: 100;
}

.v3-sidebar .v3-logo {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: var(--c-accent);
  color: var(--c-accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  margin-bottom: var(--sp-lg);
  flex-shrink: 0;
}

.v3-nav-item {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text-3);
  position: relative;
  transition: color .12s, background .12s;
  cursor: pointer;
  border: none;
  background: transparent;
}

.v3-nav-item:hover {
  color: var(--c-text-2);
  background: var(--c-surface-2);
}

.v3-nav-item.active {
  color: var(--c-accent);
  background: var(--c-accent-bg);
}

.v3-nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--c-accent);
  border-radius: 2px;
}

.v3-sidebar .v3-spacer { flex: 1; }

/* ─── Main Area ─── */
.v3-main {
  position: relative;  /* v74:为 .v3-content 绝对定位提供上下文,绕开 Chrome83 flex+overflow 高度 bug */
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100vh;
  height: 100dvh;
}

/* ─── Ticker ─── */
/* v74:绝对定位钉顶(脱离 flex 流),与 page-header/content 三层堆叠,绕开 Chrome83 flex 弹性高度 bug */
/* v237(2026-08-04): 跑马灯 .v3-ticker 整块已删(主人定删, 顶部清爽只留标题栏+头像) */

/* ─── Content Area (scrollable) ─── */
/* v74(2026-07-10):绝对定位钉死边界,根治小米8 Chrome83 滚动失效。
   真因:老 WebView 对 flex:1 撑开的"弹性高度"不当固定边界 → overflow-y:auto 不触发滚动
   (v71 manipulation→v72 pan-y→v73 删 touch-action 三连修全废,因根因不在触摸属性在容器边界)。
   解法:position:absolute 用 top+bottom 钉死固定高度,绕开 flex 弹性高度,老内核 absolute+overflow 最稳。 */
.v3-content {
  position: absolute;
  top: calc(var(--safe-top) + var(--header-h, 44px));  /* v237: ticker 已删, +safe-top 避状态栏 */
  /* v75(2026-07-10)治本★:Chrome83 MIUI WebView 对 absolute top+bottom 高度计算 bug
     (横幅实测 .v3-content h=0px clientH=0 → overflow 无滚动空间,v71~v74 四连修全废根因)。
     删 bottom:0 改显式 height calc,100% 相对 .v3-main 固定 height,老内核直接拿固定高度触发 overflow。 */
  left: 0;
  right: 0;
  height: calc(100vh - var(--safe-top) - var(--header-h, 44px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;  /* 旧 MIUI WebView(小米8)触摸惯性滚动兼容 */
  overflow-x: hidden;
  padding: 0 28px;
}

/* ─── Page Container ─── */
.v3-page {
  display: none;
}

.v3-page.active {
  display: block;
  animation: page-fade .15s ease;
  padding-top: var(--sp-xl);
}

/* Chat overrides its own padding */
#page-chat.active {
  padding-top: 0;
}

@keyframes page-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ─── Bottom Nav (Mobile) ─── */
.v3-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  z-index: 100;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
}

.v3-bottom-nav-inner {
  display: flex;
  height: var(--bottom-nav-h);
}

.v3-bnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: var(--t-meta);
  color: var(--c-text-3);
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: color .12s;
}

.v3-bnav-item.active {
  color: var(--c-accent);
}

/* 2026-08-18 演示站支付入口: 底部导航"开通"按钮金色高亮 */
.v3-bnav-pay {
  background: linear-gradient(135deg, #FFD700, #FFA500);
  color: #1a1a24 !important;
  border-radius: 8px;
  margin: 0 4px;
}
.v3-bnav-pay svg { fill: #1a1a24; }

.v3-bnav-item svg {
  width: 20px; height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}


/* ─── Dashboard header ─── */
.v3-dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
}

/* ─── Targets toolbar ─── */
.v3-targets-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════
   Mobile Breakpoint
   ═══════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .v3-sidebar { display: none; }
  .v3-bottom-nav { display: block; }

  .v3-main {
    margin-left: 0;
    height: calc(100vh - var(--bottom-nav-h) - env(safe-area-inset-bottom, 0px) - 8px);
    height: calc(100dvh - var(--bottom-nav-h) - env(safe-area-inset-bottom, 0px) - 8px);
  }

  .v3-content {
    /* v76(2026-07-10):移动端用 vh 绝对单位算高度(减 ticker/header/bottom-nav/safe/8px)。
       v75 用 100% 百分比在 Chrome83 算成0(依赖包含块解析 bug),改 vh 绝对单位 + JS px 兜底根治。 */
    height: calc(100vh - var(--header-h, 44px) - var(--bottom-nav-h) - env(safe-area-inset-bottom, 0px) - 8px);
    padding: 0 var(--sp-lg);
  }

  .v3-page-header {
    padding: var(--sp-xs) var(--sp-lg);
  }
}

/* ═══ APK 套壳强制移动端布局(2026-08-03 治铃铛左下角) ═══ */
/* APK WebView 横屏/平板/老内核 viewport 异常致 innerWidth>768,@media(max-width:768px) 不匹配,
   sidebar 没隐藏+铃铛没 fixed。html.is-apk(由 index.html UA 检测同步注入)强制走移动端布局,
   摆脱宽度依赖。与上面 @media 规则重复(媒体查询与 class 不可共用选择器,接受小幅 DRY 违反双路覆盖)。 */
.is-apk .v3-sidebar { display: none; }
.is-apk .v3-bottom-nav { display: block; }
.is-apk .v3-main {
  margin-left: 0;
  height: calc(100dvh - var(--bottom-nav-h) - env(safe-area-inset-bottom, 0px) - 8px);
}
.is-apk .v3-content {
  height: calc(100vh - var(--header-h, 44px) - var(--bottom-nav-h) - env(safe-area-inset-bottom, 0px) - 8px);
  padding: 0 var(--sp-lg);
}

/* ─── Hide all scrollbars ─── */
* {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}
*::-webkit-scrollbar {
  display: none !important;
}

/* ─── Page Header (between ticker and content) ─── */
/* v74:绝对定位钉在 ticker 下方(脱离 flex 流),与 ticker/content 三层堆叠。
   background 防 content 滚动内容透出;只有 dashboard 页 display 显示,其他页 JS 设 display:none 高0 */
.v3-page-header {
  position: absolute;
  top: var(--safe-top);  /* v237: ticker 已删, 顶栏直接贴状态栏下 */
  left: 0; right: 0;
  z-index: 2;
  background: var(--c-bg);
  flex-shrink: 0;
  padding: var(--sp-sm) 28px var(--sp-xs);
  border-bottom: 1px solid var(--c-border);
  display: flex;        /* v237: 拆左右两区——左区 .v3-ph-title(dashboard 填标题) + 右区 .v3-ph-actions(🔔+👤全局) */
  align-items: center;
  gap: var(--sp-sm);
}
.v3-page-header .v3-ph-title { flex: 1; min-width: 0; overflow: hidden; }
.v3-page-header .v3-ph-actions { flex-shrink: 0; display: flex; gap: 8px; align-items: center; }
/* v240: PC 端右区恢复显示(主题切换+🔔+👤) — 通知/主题/账号入口全端统一, 不再只靠 sidebar */
/* v241(2026-08-04): PC 删顶栏——sidebar footer 承载主题/🔔/👤, 顶栏仅移动端显简短页名。
   html:not(.is-apk) 排除 APK 套壳(横屏 viewport>769 仍走移动布局保页名, 🔴4 同源坑)。
   --header-h 由 app.js _isDesktop() 设 0(PC)/44(移动), 此处 CSS 仅 display 兜底。 */
@media (min-width: 769px) {
  html:not(.is-apk) .v3-page-header { display: none; }
}
