/* ==========================================================================
   PM 系统 · 移动端适配层
   --------------------------------------------------------------------------
   只在窄屏（<= 820px）生效，桌面端零影响。
   目标：① 无横向滚动 ② 可点 >= 40px ③ 字号 >= 12.5px ④ 表格容器内滚动
   说明：这一层要用 !important —— 各页面有自己的内联/局部样式，
        不加权的覆盖在细节上会被顶掉（实测 thead 粘性、11px 表头都因此漏改）。
   ========================================================================== */

@media (max-width: 820px) {

  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 15px; }

  /* ── 1) 防溢出：网格/弹性子项必须可收缩 ────────────────────────── */
  .users-grid > *, .form-grid > *, .page-options > *,
  .stats-row > *, .pa-grid > *, .ph-grid > *, .wb-wrap > *,
  .users-grid, .form-grid, .page-options,
  .panel, .card, .users-hero, .users-shell { min-width: 0 !important; }
  .users-grid, .form-grid, .page-options { grid-template-columns: 1fr !important; }
  .panel, .card, .users-hero { max-width: 100% !important; }

  /* ── 2) 留白收紧 ──────────────────────────────────────────── */
  .content { padding: 14px 12px 34px !important; }
  .users-shell { padding: 14px 12px 30px !important; }
  .users-hero { padding: 20px 16px !important; border-radius: 18px !important; }
  .users-hero h1, .hero-head h1 { font-size: 21px !important; }
  .card { padding: 14px !important; }
  .page-header { margin-bottom: 12px; gap: 10px; }
  .page-header h1 { font-size: 18px !important; line-height: 1.3; }

  /* ── 3) 表格：自身横向滚动，绝不撑破页面 ────────────────────────
     关键点：粘性表头在 display:block 的表格里会脱离容器宽度，
     必须复位成 static，否则整页仍被撑开。 */
  table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  thead, th { position: static !important; }
  table th, table td {
    font-size: 13px !important;
    padding: 10px 12px !important;
    white-space: nowrap;
  }
  table::-webkit-scrollbar { height: 6px; }
  table::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

  /* ── 4) 可点元素 40px 起 ───────────────────────────────────── */
  .btn, button, .chip, .range-chip, select, a.btn, a.chip, a.range-chip {
    min-height: 44px;
  }
  input:not([type=checkbox]):not([type=radio]):not([type=hidden]),
  textarea, .input { min-height: 44px; }

  /* 表格行内按钮紧凑些，但仍要够点 */
  .btn-sm, .btn.btn-xs, .btn-xs, .row-actions .btn, .actions-cell .btn {
    min-height: 38px !important;
    min-width: 44px;
    padding: 0 12px !important;
    font-size: 13px !important;
  }

  .nav-item { min-height: 46px; }
  .menu-btn { min-width: 44px; }
  .tb-logout { min-height: 40px; display: inline-flex; align-items: center; }

  /* ── 5) 输入框 16px：避免 iOS 聚焦自动放大 ──────────────────── */
  .input, .form-input, input, select, textarea { font-size: 16px !important; }

  /* ── 6) 弹层接近全屏 ─────────────────────────────────────── */
  .modal, .modal-card, .modal-box, .dialog {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 90vh;
    overflow: auto;
    border-radius: 14px;
  }
  .modal-overlay, .overlay { padding: 12px; }
  .drawer-body { width: 100% !important; max-width: 100%; }

  /* ── 7) 侧栏抽屉 ─────────────────────────────────────────── */
  .sidenav { width: 272px; }
  .sidenav .nav-item { padding: 12px !important; }
  .sidenav .nav-item .nav-lbl { font-size: 14.5px !important; }

  /* ── 8) 顶栏 ────────────────────────────────────────────── */
  .topbar { padding: 0 12px; }
  .tb-title { font-size: 15px; }
  .srm-user-badge { font-size: 12.5px; padding: 4px 9px; }

  /* ── 9) 工具栏铺满 ───────────────────────────────────────── */
  .ph-toolbar { gap: 8px; padding: 10px; }
  .ph-toolbar .ph-search,
  .ph-toolbar select { flex: 1 1 100%; max-width: none; min-height: 44px; }

  /* ── 10) 字号下限：11px 的小字全抬到 12.5 ──────────────────── */
  th, td, .order-pill, .stat-label, .stat-chip, .qty-detail,
  .task-status, .status-badge, .nav-sec, .metric-label,
  small, .hint, .lbl-hint, .wb-hint, .badge, .status-pill {
    font-size: 12.5px !important;
  }
  .tb-sub { font-size: 11px !important; letter-spacing: .1em; }
  .card-title, .card h3 { font-size: 15px; }

  /* ── 11) 按钮组换行 ──────────────────────────────────────── */
  .hero-actions, .page-header-actions, .actions-cell, .row-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
}

@media (max-width: 380px) {
  .content { padding: 12px 10px 30px !important; }
  .card { padding: 12px !important; }
  .page-header h1 { font-size: 17px !important; }
}

/* ── 12) 修正：38px 仍偏小，统一提到 40px 起 ────────────────────── */
@media (max-width: 820px) {
  .btn-sm, .btn.btn-xs, .btn-xs, .row-actions .btn, .actions-cell .btn,
  .list-panel .btn, .page-option .btn {
    min-height: 40px !important;
    min-width: 44px;
    padding: 0 12px !important;
    font-size: 13px !important;
  }

  /* 复选框/单选框本体保持小巧，但把外层 label 撑到可点面积 */
  input[type=checkbox], input[type=radio] {
    width: 20px !important;
    height: 20px !important;
    min-height: 20px !important;
    margin: 0 8px 0 0;
    vertical-align: middle;
  }
  .page-option {
    min-height: 52px !important;
    padding: 10px 12px !important;
    display: flex !important;
    align-items: center;
    gap: 8px;
  }
  .page-option input { flex: none; }

  .drawer-close { min-width: 40px !important; min-height: 40px !important; }

  /* 表格里的小字标签 */
  .pc-orders, .order-pill, .qty-detail, .stat-label {
    font-size: 12.5px !important;
  }
}

/* ── 13) 收尾：仍偏小的业务标签 ─────────────────────────────── */
@media (max-width: 820px) {
  .tag-mini, .tag, .badge, .status-pill, .nav-sec, .metric-label,
  .pivot-eyebrow, .viz-eyebrow {
    font-size: 12px !important;
  }
  /* 顶栏副标题是装饰性 kicker，保持小巧，不参与正文可读性要求 */
  .tb-sub { font-size: 10.5px !important; }
}

/* ── 14) 微标签统一 12px（此前散落 11/11.5px） ────────────────── */
@media (max-width: 820px) {
  .page-tag, .page-header-stat span, .metric-card span, .metric-card strong,
  .action-btn, .form-item, .form-item label, .pk-group-meta, .select-wrap,
  .filters-grid label, .filters-grid input, .filters-grid select,
  .stat-label, .stat-value, .hero-chip, .filter-chip, .pk-meta,
  .pill, .tag, .kicker, .eyebrow {
    font-size: 12px !important;
  }
  /* 表格里的操作小按钮文字 */
  td .action-btn, td .btn, .flat-table .btn, .table .btn {
    font-size: 12.5px !important;
  }
}

/* ── 15) 优先级修正 ─────────────────────────────────────────────
   页面里存在 .flat-table th / .table-heading p 这类 (0,1,1) 选择器，
   单写 table th (0,0,2) 即使加 !important 也赢不了（!important 也比优先级）。
   这里用重复类名把优先级提到 (0,2,1) 稳定压过它们。 */
@media (max-width: 820px) {
  .flat-table.flat-table th, .flat-table.flat-table td,
  .table.table th, .table.table td,
  .data-table.data-table th, .data-table.data-table td,
  .list-panel.list-panel th, .list-panel.list-panel td {
    font-size: 13px !important;
    padding: 10px 12px !important;
    white-space: nowrap;
  }

  .hero-description.hero-description,
  .pivot-style-label.pivot-style-label,
  .range-info.range-info,
  .table-heading.table-heading p,
  .pk-header.pk-header p,
  .pk-group-card .pk-group-meta,
  .filters-shell .range-info {
    font-size: 12.5px !important;
  }

  td .btn.btn-xs, td .btn.btn-sm,
  .flat-table .btn.btn-xs, .table .btn.btn-xs {
    font-size: 12.5px !important;
    min-height: 40px !important;
  }
}

/* ── 16) 表格内状态小标签 12px ─────────────────────────────── */
@media (max-width: 820px) {
  table td span, table td small {
    font-size: 12px !important;
  }
  .pivot-overtime-dot.pivot-overtime-dot,
  .status-badge.status-badge,
  td .task-status.task-status,
  td .qty-detail.qty-detail,
  .range-info.range-info {
    font-size: 12px !important;
  }
  /* 表格单元格本身不允许小过 12.5 */
  .flat-table.flat-table td, .table.table td,
  .data-table.data-table td, .list-panel.list-panel td {
    font-size: 13px !important;
  }
}

/* ── 17) 最后一档：卡片内段落与图表标签 ─────────────────────── */
@media (max-width: 820px) {
  .card.card p, .card.card span, .card.card label,
  .chart-total-label.chart-total-label,
  .pk-header .card.card p {
    font-size: 12.5px !important;
  }
}

/* ── 18) 兜底：正文区里没有 class 的裸 span/small ──────────────
   这类元素无法按类名命中，用属性选择器一次覆盖；
   它能命中 (0,2,1) 优先级，稳定压过 .flat-table td span 之类。
   只影响纯文本小片，不触碰有类名的图标/组件。 */
@media (max-width: 820px) {
  main.content span:not([class]),
  main.content small:not([class]),
  small {
    font-size: 12.5px !important;
  }
}

/* ── 19) 兜底（全局范围）：无 class 的行内文本元素 ──────────────── */
@media (max-width: 820px) {
  body span:not([class]),
  body small:not([class]),
  body label:not([class]),
  body b:not([class]),
  body strong:not([class]) {
    font-size: 12.5px !important;
  }
}

/* ── 手机端常驻拍照按钮 ─────────────────────────────────────── */
.pm-fab-cam { display: none; }
@media (max-width: 820px) {
  .pm-fab-cam {
    position: fixed; right: 16px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    z-index: 45;
    display: inline-flex; align-items: center; gap: 7px;
    height: 52px; padding: 0 20px 0 16px;
    border-radius: 999px;
    background: var(--accent); color: #fff;
    font-size: 15px; font-weight: 700; letter-spacing: .02em;
    text-decoration: none;
    box-shadow: 0 10px 24px -8px rgba(0,87,210,.55);
    transition: transform .14s ease, background .14s ease;
  }
  .pm-fab-cam:hover { background: var(--accent-strong); color: #fff; text-decoration: none; }
  .pm-fab-cam:active { transform: scale(.96); }
  .pm-fab-cam svg { width: 21px; height: 21px; flex: none; }
  /* 给内容留出按钮高度，避免挡住表格最后一行 */
  .content { padding-bottom: 104px !important; }
}
