/* public/styles/layout.css
 * 顶栏 / 侧栏 / 主区网格 + ≤768px 底部 Tab Bar + 响应式
 * 顶栏高 48（桌面）/ 52（移动，PRD §2.7）；仅顶栏与移动底部 Tab 允许 backdrop-filter（PRD §2.6）。
 */

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 48px 1fr;
  /* 应用外壳：固定为视口高 → grid 的 1fr 行得到确定高度，.main 的 overflow 才真正生效，
     内容被裁剪/滚动在 .main 内部，而不会“长到文档里去”。这是「悬浮层不遮挡内容」的前提：
     若用 min-height，.app 会随内容增高、整页滚动，固定定位的 Tab Bar / FAB 便会在
     每个滚动位置压住正文（见反馈问题 3）。 */
  /* 移动端动态视口：iOS Safari / Android Chrome 的地址栏/工具栏会动态伸缩，
     100vh 取的是「工具栏收起」时的最大高度 → 工具栏展开时底部会被裁掉。
     100dvh 跟踪动态视口高度，配合固定的底部 Tab Bar 让位于视口底。 */
  height: 100vh;    /* 回退：不支持 dvh 的旧浏览器 */
  height: 100dvh;   /* 动态视口：现代浏览器（后者覆盖前者） */
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  height: 48px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  /* 仅顶栏允许毛玻璃（PRD §2.6） */
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* 品牌区（logo + 观复 + 小字 Almanac） */
.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  white-space: nowrap;
}
.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  flex: none;
}
.brand-logo img { width: 100%; height: 100%; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; font-size: var(--fs-body); letter-spacing: .02em; color: var(--text-primary); }
.brand-en { font-size: var(--fs-micro); letter-spacing: .18em; color: var(--text-faint); text-transform: uppercase; }

.brand-sub { color: var(--text-faint); font-size: var(--fs-xs); font-weight: 400; letter-spacing: .12em; }

/* 桌面：品牌只在侧栏顶部；顶栏品牌仅移动端显示（避免重复） */
.topbar-brand { display: none; }

.topbar-spacer { flex: 1; }

/* 侧栏顶部品牌区（logo + 观复 + 小字 Almanac） */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3) var(--sp-4);
}
.sidebar-brand .brand-logo { width: 30px; height: 30px; }

/* 顶栏插槽：同步状态（W11）/ 提醒中心（W12）挂载点 */
.topbar-slot { display: inline-flex; align-items: center; }
.topbar-actions { display: inline-flex; align-items: center; gap: var(--sp-2); }

.search-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 220px;
  height: 32px;
  padding: 0 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-faint);
  cursor: pointer;
  text-align: left;
}
.search-btn kbd {
  margin-left: auto;
  font-size: var(--fs-micro);
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 0 5px;
}
.search-btn:hover { border-color: var(--border-strong); }

/* 能力状态芯片 */
.cap-chip { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--text-secondary); flex: none; white-space: nowrap; }
.cap-dot { width: 8px; height: 8px; border-radius: var(--r-pill); background: var(--success); display: inline-block; }
.cap-dot.warn { background: var(--warning); }
.cap-dot.info { background: var(--m-info); }

/* ---------------- 侧栏 ---------------- */
.sidebar {
  grid-column: 1;
  grid-row: 2;
  background: var(--bg-base);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-2);
}
.side-group-label {
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
  font-size: var(--fs-micro);
  color: var(--text-faint);
  letter-spacing: .14em;
  text-transform: uppercase;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: 4px var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: none;
  border: none;
  transition: background-color var(--dur-base) var(--ease-out);
}
.nav-item:hover { background: var(--bg-surface-2); color: var(--text-primary); }
.nav-item .nav-icon { display: inline-flex; width: 18px; justify-content: center; color: var(--text-faint); flex: none; }
.nav-item .nav-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.nav-item .nav-main { font-size: var(--fs-body); color: var(--text-primary); }
.nav-item .nav-sub { font-size: var(--fs-micro); color: var(--text-faint); letter-spacing: .06em; }
.nav-item.active {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: var(--r-pill);
  background: var(--accent);
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-item.active .nav-main { color: var(--accent); font-weight: 600; }
.nav-item.active .nav-sub { color: var(--accent); }
.nav-item.disabled { color: var(--text-faint); pointer-events: none; }
.nav-item .nav-count {
  margin-left: auto;
  font-size: var(--fs-micro);
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--r-pill);
  padding: 0 6px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.sidebar-foot {
  margin-top: var(--sp-5);
  padding: var(--sp-3) var(--sp-3);
  color: var(--text-faint);
  font-size: var(--fs-xs);
  border-top: 1px solid var(--border);
}

/* ---------------- 主区 ---------------- */
.main {
  grid-column: 2;
  grid-row: 2;
  overflow-y: auto;
  padding: var(--pad-page-y) var(--pad-page-x);
  /* 允许主区在窄屏随容器收缩（grid 项默认 min-width:auto 会被内容撑破） */
  min-width: 0;
  font-size: var(--fs-page);
}

/* 内容最大宽度 + 居中：超宽屏（≥1600）行宽不再被拉长，信息更集中（任务 B） */
#view {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
}

.view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.view-title { font-size: var(--fs-h1); font-weight: 700; line-height: var(--lh-tight); }
.view-sub { color: var(--text-secondary); font-size: var(--fs-sm); }

/* ---------------- 工具栏（sticky 吸顶）---------------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  height: 48px;
  padding: 0 var(--sp-4);
  /* 与 .main 的流体水平内边距一致，使吸顶工具栏两端贴合主区边缘 */
  margin: calc(-1 * var(--pad-page-y)) calc(-1 * var(--pad-page-x)) var(--sp-4);
  background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}
.toolbar .spacer { flex: 1; }

/* ---------------- 移动端底部 Tab Bar（5 项）---------------- */
.tabbar {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 56px;
  background: var(--topbar-bg);
  border-top: 1px solid var(--border);
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom, 0);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px; /* DP-4：移动端点击目标 ≥ 44×44 */
  font-size: var(--fs-micro);
  color: var(--text-faint);
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px 0;
}
.tab.active { color: var(--accent); }
.tab svg { width: 20px; height: 20px; }

/* =========================================================================
 * 响应式：平板 + 手机（≤1024）—— 统一「移动布局」
 * -----------------------------------------------------------------------------
 * 设计意图（DESIGN-增量 §2.F / PRD §5.4）：平板（769–1024）与手机（≤768）一致，
 * 使用底部 Tab 栏、隐藏侧栏；可点元素 ≥44px、输入 ≥16px、安全区适配。
 *
 * 实现说明：底部 Tab 栏 / 侧栏的显隐由本文件的 CSS 媒体查询驱动
 *（app.js 的 buildSidebar / buildTabbar 始终构建 DOM、不随视口切换），
 * 故「把断点由 ≤768 提到 ≤1024」即把下列布局规则从原 ≤768 块上移至此。
 * 触控目标（.btn / .icon-btn / .chip / .tab-btn / .toggle / select 等）的
 * ≥44px 与输入字号 ≥16px 规则见 components.css 的 ≤1024 块，避免同选择器两文件重复。
 * ========================================================================= */
@media (max-width: 1024px) {
  /* —— 布局：单栏 + 底部 Tab 栏，隐藏侧栏 —— */
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr;
    /* 底部 chrome 让位（Tab Bar 56 + FAB 悬浮区）；含 iOS 安全区 inset。
       平板同样隐藏侧栏、显示底栏，故让位规则一并上移。 */
    padding-bottom: calc(136px + env(safe-area-inset-bottom, 0px));
  }
  .sidebar { display: none; }
  .topbar { height: 52px; gap: var(--sp-2); }
  .topbar-brand { display: flex; }
  .brand-logo { width: 24px; height: 24px; }
  .main {
    grid-column: 1;
    grid-row: 2;
    padding: var(--sp-4);
  }
  .tabbar { display: flex; }
  /* 移动端捕获入口唯一化：隐藏顶栏「快速捕获」，FAB（capture.js 在 ≤768 提供） */
  #capture-trigger { display: none; }
  /* 工具栏负外边距与移动端 .main 内边距（--sp-4）对齐 */
  .toolbar { margin: calc(-1 * var(--sp-4)) calc(-1 * var(--sp-4)) var(--sp-4); }
  .view-title { font-size: var(--fs-h1); }

  /* —— 触控兜底（layout 层负责的几项）——
     更细的触控目标与输入字号 ≥16px 见 components.css ≤1024 块。 */
  /* `.search-btn` 基础样式是 `height:32px`（固定行高），补 min-height 使其 ≥44
     （topbar 行高 ≥56，容得下）；宽度已 ≥185 无需补。
     平板档原先缺失这条，实测 search-btn = 185×32，仍有 10 处触控违规。 */
  .search-btn { min-width: var(--tap-min); min-height: var(--tap-min); }
  .search-btn .search-label { display: none; }
  /* 窄屏精简顶栏：隐藏非必要文字/快捷键，避免撑破视口引发横向滚动 */
  .search-btn kbd { display: none; }
  /* .cap-chip 是真实点击目标（app.js 点击懒请求通知权限），补高度到 44；
     宽度已 ≥85 无需补。 */
  .cap-chip { min-height: var(--tap-min); }
}


/* 极窄屏（≤560）：能力芯片收紧间距。
   （顶栏「快速捕获」已在 ≤768 隐藏，顶栏空间充裕，故此处**保留状态文案** ——
   使「本地能力可用」在全宽度区间都恰好出现 1 次，作为该状态文案的唯一来源。
   同时隐去品牌的小字「ALMANAC」，为状态文案让出横向空间、避免其换行/溢出。） */
@media (max-width: 560px) {
  .cap-chip { gap: var(--sp-1); }
  .topbar-brand .brand-en { display: none; }
}

/* 极窄屏（≤360 CSS px；真机如 iPhone SE 一代 320×568。
   注意：顶栏 7 个子元素在 ≤768 档的横向预算约 350px，故 **任意 width < 350** 都会把文档
   撑出横向滚动（320px 实测 scrollWidth 350 > clientWidth 320，右侧余量 −13.5px）；
   375px 通过但余量仅 16px，很薄。此处仅在极窄档收紧「间距 / 顶栏内边距 / 搜索钮内边距」三项
   （合计省约 48px），让内容**真实塞得下**（不裁剪、不隐藏、不缩触控目标）。
   不动桌面呈现（1440/1024 不受此媒体查询影响）；#cap-text「本地能力可用」仍唯一可见。 */
@media (max-width: 360px) {
  .topbar { gap: var(--sp-1); padding: 0 var(--sp-2); }
  .search-btn { padding: 0 6px; }
}

/* 打印（报告导出为 PDF 视图） */
@media print {
  .topbar, .sidebar, .tabbar, .no-print { display: none !important; }
  .app { display: block; }
  .main { padding: 0; overflow: visible; }
  body { background: #fff; }
}
