/* ═══════════════════════════════════════════════════
   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;
  z-index: 1;  /* 动效批3(4B): 内容画在 .v3-snav-block 滑动背景块之上 */
  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);
  /* 动效批3(4B): active 背景改由 .v3-snav-block 滑动块接管(静态背景会跟滑动块双显破坏动画) */
  background: transparent;
}

/* 动效批3(4B) 侧栏背景块滑动: rect 由 JS 实测 active item offset 设值, 只管动画 */
.v3-snav-block {
  display: none;  /* JS _moveNavDecor 首次定位后才 display:block — none→block 不播 transition, 天然跳过首帧 (0,0) 飞入 */
  position: absolute;
  border-radius: var(--radius-md);
  background: var(--c-accent-bg);
  transition: top .28s cubic-bezier(.3, 1.2, .4, 1);
  z-index: 0;
  pointer-events: none;
}

.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;
  /* page-fade 已删(v472c): 切页进场由 2A 位移滑入接管; 这行淡入会在 2A end 摘 class 后
   * 因 animation-name 回落而重播 opacity 0→1 = 切页闪第二下(旧页瞬删+新页 opacity0 起始帧露 body 底色) */
  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);
  position: relative;  /* 动效批3(3A): .v3-bnav-pill 滑动胶囊的定位上下文 */
}

/* 动效批3(3A) 底部导航金色胶囊: 等宽 flex:1 下 translateX(idx*100%) 滑到 active tab(demo p3-pill 参数) */
.v3-bnav-pill {
  position: absolute;
  top: 5px; bottom: 5px; left: 0;
  width: 20%;
  border-radius: 12px;
  background: var(--c-accent-bg);
  transform: translateX(0);
  transition: transform .3s cubic-bezier(.3, 1.3, .4, 1);
  z-index: 0;
  pointer-events: none;
}

.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;
  position: relative;
  z-index: 1;  /* 动效批3(3A): 内容画在 .v3-bnav-pill 滑动胶囊之上 */
}

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

.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; }
  /* v386c(2026-08-31 主人报"PWA下 composer 与底部菜单之间一片空白"): 全局 border-box 下
     nav 的 height:56px 已含 padding-bottom(safe+8), nav 实际只占 56px; 而内容区高度链减了 56+safe+8
     → 多减的 safe+8(iPhone PWA ~42px)露 html 深黑底成空白; 浏览器被系统条遮住看不见, PWA
     standalone(viewport-fit=cover)完全暴露。修法: nav 高度把 safe+8 吃进来做 surface 背景
     (inner 仍 56 顶置), 与 .v3-main/.v3-content 高度链减项(56+safe+8)重新对齐 → composer 底=nav 顶无缝 */
  .v3-bottom-nav { height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 8px); }

  .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 兜底根治。
       v386d(2026-08-31):补 var(--safe-top) 减项——v237 加 safe-top 时基础样式减了但移动端覆盖漏了,
       致 PWA 下 content top 下移 47px 但 height 没同步减,底部伸进 nav 区域 47px 被遮 */
    height: calc(100vh - var(--safe-top) - 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; height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 8px); }  /* v386c 同上: border-box 下 nav 吃掉 safe+8, 与高度链减项对齐 */
.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 {
  /* v386d:同步移动端修复,补 var(--safe-top) 减项 */
  height: calc(100vh - var(--safe-top) - 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; }
}
