/**
 * 移动端 / PWA 样式：与 site.css 分离，改桌面版式时不必在本文件里来回翻。
 *
 * 三块内容：
 *   ① ≤760px 的重排：底部标签栏、表格转卡片、全宽表单、更大触控尺寸
 *   ② 图片灯箱（全宽度生效，桌面端也能用滚轮缩放）
 *   ③ PWA 独立窗口下的安全区与滚动修正
 */

/* ===== ① 窄屏重排 ===== */
@media (max-width: 760px) {
  :root { --tab-h: 54px; }

  html { -webkit-text-size-adjust: 100%; }

  /* 顶栏：只留品牌 + 只读徽标 + 退出，导航交给底部标签栏（原先 nav 被挤成 0 宽而"消失"） */
  .topbar {
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    gap: 10px;
    flex-wrap: nowrap;
  }
  .seal { width: 24px; height: 24px; font-size: 13px; }
  .brand__name { font-size: 15.5px; }
  .brand__tag { display: none; }
  .nav { display: none; }
  .topbar__right { margin-left: auto; flex: 0 0 auto; gap: 6px; }
  .topbar__right .ver { display: none; }

  /* 给底部标签栏留出空间，避免最后一屏内容被挡住（登录页 / 分享页没有标签栏，不加） */
  .main { padding: 14px 12px 20px; }
  .foot {
    padding: 12px 14px 22px;
    font-size: 11.5px; line-height: 1.7;
  }
  body.has-tab .foot { padding-bottom: calc(var(--tab-h) + 22px + env(safe-area-inset-bottom)); }

  /* 底部标签栏：拇指可达，5 项均分 */
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -1px 0 rgba(31, 42, 40, 0.04);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  .tabbar__item {
    flex: 1 1 0; min-width: 0; height: var(--tab-h);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--ink-soft); font-size: 10.5px; letter-spacing: 0.02em;
    -webkit-tap-highlight-color: transparent;
  }
  .tabbar__item .ico { width: 21px; height: 21px; }
  .tabbar__item.is-on { color: var(--teal); font-weight: 600; }
  .tabbar__item:active { background: var(--teal-soft); }

  /* 标题与页头 */
  .phead { margin-bottom: 12px; }
  .phead__title { font-size: 19px; line-height: 1.35; }
  .phead__sub { font-size: 12px; }
  .phead__acts { gap: 6px; }
  .h1 { font-size: 18px; }
  .card { padding: 12px 13px; }
  .card--narrow { margin: 26px auto; }

  /* 触控目标：按钮至少 40px 高；输入框 16px 字号避免聚焦时被自动放大 */
  .btn { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 8px 14px; }
  .btn--sm { min-height: 32px; padding: 5px 11px; }
  .input, .sel { min-height: 40px; font-size: 16px; }
  .chip { padding: 6px 12px; font-size: 13px; }

  /* 筛选栏：搜索独占一行，下拉两列，按钮等分 */
  .filters { gap: 8px; }
  .filters .input { flex: 1 1 100%; }
  .filters .sel { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filters .btn { flex: 1 1 0; }

  /* 统计 / 条形 */
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat { padding: 10px; }
  .stat__num { font-size: 20px; }
  .bar { grid-template-columns: 44px 1fr 40px; gap: 8px; }

  /* ===== 表格 → 卡片（data-label 取值由服务端渲染时写入） ===== */
  .tbl { background: transparent; border: 0; border-radius: 0; overflow: visible; }
  .tbl table { display: block; width: 100%; table-layout: auto; min-width: 0; }
  .tbl colgroup, .tbl thead { display: none; }
  .tbl tbody { display: block; }
  .tbl tbody tr {
    display: block; margin-bottom: 8px; padding: 10px 12px;
    background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px;
  }
  .tbl tbody tr:last-child { margin-bottom: 0; }
  .tbl th, .tbl td {
    display: flex; align-items: baseline; gap: 10px;
    border: 0; padding: 2px 0; border-bottom: 0;
    white-space: normal; overflow: visible; text-overflow: clip;
    font-size: 13.5px; line-height: 1.6;
  }
  .tbl td::before {
    content: attr(data-label);
    flex: 0 0 60px; color: var(--ink-soft); font-size: 12px;
  }
  .tbl td.num, .tbl th.num { text-align: left; }
  .tbl td.ttl {
    display: block; padding: 0 0 6px;
    font-size: 15.5px; font-weight: 600; line-height: 1.45;
  }
  .tbl td.ttl::before { display: none; }
  .tbl .empty, .tbl td.empty { display: block; text-align: center; padding: 18px 0; }
  .tbl .empty::before, .tbl td.empty::before { display: none; }
  .pfoot { flex-direction: column; gap: 8px; align-items: stretch; text-align: center; }
  .pager { justify-content: center; }
  .pager__btn { min-height: 36px; display: inline-flex; align-items: center; padding: 2px 14px; }

  /* 详情 */
  .kv { grid-template-columns: 62px 1fr; font-size: 13.5px; }
  .sec { padding: 12px 13px; }
  .prose { font-size: 15px; line-height: 1.9; }
  .prose h1 { font-size: 19px; }
  .prose h2 { font-size: 17px; }
  .prose h3 { font-size: 15.5px; }
  .prose ul, .prose ol { padding-left: 1.5em; }

  /* 影像：两列，好点按 */
  .thumbs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .thumb img { height: 110px; }
  .thumb__link { display: block; -webkit-tap-highlight-color: transparent; }

  /* 生长曲线：表格已卡片化，图表本身随宽度缩放 */
  .chart { min-height: 180px; }

  /* 同步管理 */
  .paircode__code { font-size: 26px; letter-spacing: 0.18em; }
  .meta-grid { grid-template-columns: 1fr; }
  .pairgen { gap: 8px; }
}

/* 非常窄（≤360px）：标签文字再收一点，避免 5 项挤成两行 */
@media (max-width: 360px) {
  .tabbar__item { font-size: 10px; }
  .tabbar__item .ico { width: 19px; height: 19px; }
  .tbl td::before { flex: 0 0 52px; }
}

/* 横屏手机：底部标签栏仍在，但收紧上边距 */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 480px) {
  :root { --tab-h: 46px; }
  .main { padding-top: 10px; }
}

/* ===== ② 图片灯箱（全宽度） ===== */
.lb { position: fixed; inset: 0; z-index: 900; display: none; background: rgba(10, 16, 15, 0.95); }
.lb.is-open { display: block; }

.lb__stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: none; cursor: grab;
}
.lb__stage.is-zoomed { cursor: grabbing; }

.lb__img {
  max-width: 100%; max-height: 100%;
  transform-origin: center center;
  will-change: transform;
  -webkit-user-select: none; user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

.lb__bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  color: #fff; font-size: 12.5px;
  pointer-events: none;
}
.lb__count { opacity: 0.75; font-variant-numeric: tabular-nums; }
.lb__tools { display: flex; gap: 8px; pointer-events: auto; }
.lb__btn {
  width: 38px; height: 38px; border-radius: 50%; border: 0;
  background: rgba(255, 255, 255, 0.16); color: #fff;
  font-size: 16px; line-height: 1;
  display: grid; place-items: center; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.lb__btn:active { background: rgba(255, 255, 255, 0.3); }
.lb__btn--text { width: auto; padding: 0 12px; border-radius: 999px; font-size: 12.5px; }

.lb__nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 40px; height: 56px; border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, 0.12); color: #fff; font-size: 20px;
  display: grid; place-items: center; cursor: pointer;
}
.lb__nav:active { background: rgba(255, 255, 255, 0.28); }
.lb__nav--prev { left: 8px; }
.lb__nav--next { right: 8px; }

.lb__cap {
  position: absolute; left: 0; right: 0; bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 2; padding: 0 18px;
  color: rgba(255, 255, 255, 0.82); font-size: 12px; line-height: 1.6;
  text-align: center; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

body.lb-lock { overflow: hidden; }
/* 灯箱盖住整屏后，底下的顶栏 / 标签栏不该透出来 */
body.lb-lock .topbar,
body.lb-lock .tabbar { visibility: hidden; }

/* ===== ③ PWA 独立窗口 ===== */
@media (display-mode: standalone) {
  /* iOS 独立模式下顶部安全区已由 topbar 的 padding 处理，这里只兜底滚动 */
  body { overscroll-behavior-y: none; }
}
