/* ===== #261 移动端适配层（mobile.css）=====
 * 加载于 style.css 之后 → 级联天然压过 style.css 全部后段功能样式（解决中部移动层被后段覆盖的根因）。
 * 断点收敛为两档：≤768（手机）/ ≤480（小屏手机）；平板 768-1024 沿用 style.css 既有规则。
 * 颜色一律用 var(--c-*) 承接暗色主题；桌面端（>768px）除 .m-tabbar 隐藏外零规则命中。 */

/* Tab 栏桌面隐藏（防意外渲染） */
.m-tabbar { display: none; }

/* #317 手机端专属元素（桌面隐藏，≤768 显示）：与 .fd-hide-m 镜像 */
.fd-show-m { display: none !important; }

/* ========== 手机（≤768px） ========== */
@media (max-width: 768px) {
  html { -webkit-text-size-adjust: 100%; }
  a, button, .btn, input[type="checkbox"], input[type="radio"] { touch-action: manipulation; }

  /* ---------- 壳层 ---------- */
  .sidebar { height: 100dvh; max-width: 82vw; overscroll-behavior: contain; }
  .topbar { padding-top: env(safe-area-inset-top, 0); height: calc(54px + env(safe-area-inset-top, 0)); }
  .content { padding: 12px 12px calc(128px + env(safe-area-inset-bottom, 0)); }   /* 88→128：#321 底部固定批条（勾选态出现，最多两行按钮）不遮末条目 */
  .gs-wrap { display: none; }          /* 顶栏全局搜索手机隐藏（门户内已有搜索入口） */
  .tb-title { flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ---------- 底部 Tab 栏 ---------- */
  .m-tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 90;
    background: var(--c-card); border-top: 1px solid var(--c-border);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0));
  }
  .m-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 5px 0 3px; font-size: 11px; color: var(--c-muted); cursor: pointer; text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  .m-tab-icon { font-size: 20px; line-height: 1; position: relative; }
  .m-tab-badge {
    position: absolute; top: -5px; right: -16px; background: var(--c-red); color: #fff;
    border-radius: 9px; font-size: 10px; padding: 1px 5px; min-width: 16px; text-align: center; line-height: 1.4;
  }
  .m-tab.active { color: var(--c-primary); font-weight: 600; }
  .m-tab:active { opacity: .7; }

  /* ---------- 设计器横幅 ---------- */
  .m-designer-hint {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    background: #fffbeb; color: #92400e; border: 1px solid #fde68a;
    border-radius: var(--r-md); padding: 8px 12px; margin-bottom: 10px; font-size: 13px;
  }

  /* ---------- 弹窗：底部 Sheet / 表单类全屏 ---------- */
  .modal-mask { align-items: flex-end; padding: 0; z-index: 200; }
  /* v406 琛总手机四问题修复：详情弹窗上再开的二级弹窗（选人/转交/分享）此前贴顶且 z 继承
     style.css 的 60，被 z200 的详情弹窗整层盖死（点着「没反应」、按钮永挂「处理中」）。
     统一贴底（与详情弹窗位置一致）＋层级 210 压过 200，桌面端 50/60 零变化。 */
  .modal-mask.modal-mask-top { align-items: flex-end; z-index: 210; }
  /* v406 配套：下拉搜索面板(ss-panel, 挂 body, style.css z200)必须压过二级弹窗 mask(210)，
     否则选人弹窗里点下拉「没反应」（面板弹了被 mask 盖住）。桌面端 mask 50/60 维持 200 不动。 */
  .ss-panel { z-index: 220; }
  .modal {
    width: 100% !important; max-width: 100% !important; min-width: 0 !important;
    margin: 0; max-height: 92dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .modal.fd-modal, .modal.wf-modal { height: 100dvh; max-height: 100dvh !important; border-radius: 0; }
  .modal-resize-handle { display: none; }
  .fd-modal .fd-modal-foot {
    position: sticky; bottom: 0; z-index: 5; background: var(--c-card);
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  }
  /* 输入 16px 防 iOS 聚焦自动缩放（压过各作用域 13/14px） */
  input, select, textarea { font-size: 16px !important; }

  /* ---------- 按压反馈 ---------- */
  .btn:active { opacity: .75; }

/* ---------- 门户：手机工作台形态（#265 大幅升级） ---------- */
/* Hero 品牌横幅：纵向重排（问候 → 全宽搜索 → 待办+自定义一行），装饰圈收小防溢出 */
.pt-hero { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px 16px 16px; border-radius: 14px; margin-bottom: 12px; }
.pt-hero-l { min-width: 0; }
.pt-hi { font-size: 18px; }
.pt-sub { font-size: 12px; margin-top: 2px; }
.pt-hero-search { order: 2; max-width: none; min-width: 0; }
.pt-hero-search input { padding: 11px 14px; font-size: 14px; border-radius: 10px; }   /* 14px+：iOS 聚焦不自动放大 */
.pt-hero-r { order: 3; justify-content: space-between; gap: 8px; }
.pt-hero-todo { flex: 1; justify-content: center; padding: 8px 10px; font-size: 12px; }
.pt-hero-todo b { font-size: 16px; }
/* #028 手机端隐藏「自定义门户」入口（自定义仅 PC 操作）；#043 布局来源提示已全端删除 */
.pt-hero-btn { display: none; }
.pt-hero-deco1 { width: 160px; height: 160px; right: -40px; top: -90px; }
.pt-hero-deco2 { width: 110px; height: 110px; left: 30%; bottom: -70px; }
/* 快捷入口：4 列无边框宫格（APP 工作台风），图标做视觉主体 */
.pt-quick-grid { grid-template-columns: repeat(4, 1fr) !important; gap: 6px 4px; }
.pt-quick { background: transparent; border: none; padding: 8px 2px; border-radius: 12px; }
.pt-quick-ico { width: 46px; height: 46px; margin-bottom: 6px; border-radius: 14px; font-size: 22px; }
.pt-quick-l { font-size: 11px; white-space: nowrap; }
.pt-qgroup { font-size: 11px; margin: 12px 2px 6px; }
/* 经营指标：紧凑 2×2，数字为主 */
.pt-kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pt-kpi { padding: 12px 14px; border-radius: 12px; }
.pt-kpi-v { font-size: 20px; }
.pt-kpi-t { font-size: 11px; margin-top: 2px; }
/* 钉选报表：横向滑动卡片（scroll-snap），单手浏览效率高 */
.pt-pins-wrap { display: flex !important; grid-template-columns: none !important; overflow-x: auto; gap: 10px; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; padding-bottom: 4px; scrollbar-width: none; }
.pt-pins-wrap::-webkit-scrollbar { display: none; }
.pt-pinned, .pt-pinned-tile { flex: 0 0 84%; scroll-snap-align: center; margin: 0; }
.pt-pinned-mini { min-height: 160px; }
/* 区块卡片与自由布局：紧凑化，单列已有 */
.pt-section { border-radius: 14px; padding: 12px; }
.pt-section-h { font-size: 13px; margin: 0 0 8px; }
.pt-grid { grid-template-columns: 1fr !important; gap: 12px; }
.pt-cell { grid-column: auto !important; grid-row: auto !important; min-height: 0; }
.pt-cols { grid-template-columns: 1fr; gap: 12px; }
.pt-cards { grid-template-columns: 1fr !important; }
.pt-cal-c { padding: 5px 0; }

  /* ---------- 报表查看态 ---------- */
  .rep-chart-box { height: 280px; }
  .rep-view-box { padding: 12px; }

  /* ---------- 表单容器：自由分栏手机降单列 ---------- */
  .lc-cols-flex { flex-wrap: wrap; gap: 10px 0; }
  .lc-cols-flex .lc-col-cell, .lc-cols-design .lc-col-cell { width: 100% !important; }
  .lc-cols-flex .lc-col-resizer, .lc-cols-design .lc-col-resizer { display: none; }
  .lc-tab-heads, .cf-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  /* v406 琛总实测：详情四个页签（表单信息/审批记录/讨论留言/操作日志）被压窄文字折行。
     页签不收缩+不换行，单行横滑展示；字号/内边距收紧尽量一屏放下 */
  .cf-tabs .cf-tab { flex-shrink: 0; white-space: nowrap; padding: 8px 10px; font-size: 13px; }
  .lcdate-panel { max-width: 92vw; }

  /* ---------- 卡片视图（列表页手机端） ---------- */
  .m-cards { display: flex; flex-direction: column; gap: 10px; }
  .m-card {
    background: var(--c-card); border: 1px solid var(--c-border); border-radius: var(--r-md);
    padding: 12px 14px; box-shadow: var(--sh-sm); position: relative;
  }
  .m-card:active { background: var(--c-hover); }
  .m-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; color: var(--c-muted); }
  .m-card-head .tag { font-size: 11px; }
  .m-card-head input[type="checkbox"] { width: 18px; height: 18px; }
  .m-card-selbox { display: inline-flex; align-items: center; margin-right: auto; }
  .m-card-title {
    font-size: 15px; font-weight: 600; color: var(--c-text); margin-bottom: 6px; cursor: pointer;
    overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
  .m-card-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-bottom: 6px; }
  .m-card-field { display: flex; gap: 6px; font-size: 13px; min-width: 0; align-items: baseline; }
  .m-fl { color: var(--c-muted); flex-shrink: 0; }
  .m-fv { color: var(--c-text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .m-card-meta { font-size: 12px; color: var(--c-muted); margin-bottom: 8px; }
  .m-card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
  .m-card-actions .btn { flex: none; min-height: 34px; padding: 6px 12px; }
  /* v408 白色辅助/彩色主操作分行：每行整行占满，行内按钮紧凑排列 */
  .m-card-actions .m-card-acts-row { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
  .m-cards-empty {
    text-align: center; padding: 36px 12px; background: var(--c-card);
    border: 1px dashed var(--c-border); border-radius: var(--r-md); font-size: 15px;
  }
  .m-cards-empty .muted { font-size: 12px; margin-top: 4px; }

  /* ---------- 工具栏收敛 ---------- */
  .fd-hide-m { display: none !important; }   /* 低频按钮（设计/打印模板/月度汇总等）手机隐藏 */
  .fd-show-m { display: inline-flex !important; }  /* #317 手机端专属按钮（卡片字段设置等） */
  /* #317 卡片字段设置面板：行内 ↑↓ 排序按钮组（触屏弃拖拽） */
  .fd-card-move { display: inline-flex; gap: 4px; flex-shrink: 0; margin-left: auto; }
  .fd-card-move .btn { min-height: 28px; padding: 2px 8px; font-size: 12px; }
  .fd-card-move .btn[disabled] { opacity: .35; }
  .list-search { width: 100%; }
  /* #049c 消息中心筛选行布局由 style.css .msg-filter-row 定宽接管（搜索 flex-basis 220px），此处无需覆盖 */
  .toolbar .tb-actions, .toolbar > div { width: 100%; }
  #fd_bulkbar, #sea_bulkbar, #bulkBar, #msgBulkBar { flex-wrap: wrap; }
  /* 2.0 #321 手机端批量操作条全站统一（琛总 2026-10-27「其他所有手机端的批量操作同步」）：
     勾选后固定屏幕底下＋按钮复用事件内按钮（不加「批量」二字，文案分支在各页 JS 渲染器；
     条数提示在前＋点击有批量确认弹窗）。覆盖四类批条：
     #bulkBar（我的审批 / 通用表格 CRM·用户·部门 共用元素）· #fd_bulkbar 低代码数据 ·
     #sea_bulkbar 客户公海 · #msgBulkBar 消息中心。盖过底部 Tab 栏（z 96 > 90）；
     弹窗层 200 仍在最上，批量确认弹窗不被条挡。桌面 >768 不命中本媒体块，原批条零变化。
     fd/sea 两条批条自带内联样式（margin/padding/border/border-radius），用 !important 压过 */
  #bulkBar, #fd_bulkbar, #sea_bulkbar, #msgBulkBar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 96;
    margin: 0 !important; border-radius: 0 !important;
    border-left: none !important; border-right: none !important; border-bottom: none !important;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .08);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0)) !important;
  }
  #bulkBar .btn, #fd_bulkbar .btn, #sea_bulkbar .btn, #msgBulkBar .btn { min-height: 34px; flex: none; }
  #bulkBar .bulk-count, #msgBulkBar .bulk-count { font-size: 13px; white-space: nowrap; }
  #fd_bulkbar > span:first-child, #sea_bulkbar > span:first-child { white-space: nowrap; }
  /* 表格字号回正（style.css ≤480 压到 11px 过小） */
  th, td { font-size: 13px; }
  .tag { font-size: 11px; }

  /* toast 让出刘海 */
  .toast-item { top: calc(12px + env(safe-area-inset-top, 0)); }

  /* 2.0 #027 日历日期格 +：无 hover，常显（点日期直接建日程） */
  .cal-cell-add { display: inline-flex !important; align-items: center; justify-content: center; opacity: .55; }

  /* 2.0 #045 协同人选择弹窗：两栏改上下堆叠，列表限高防小屏溢出 */
  .cal-pp-cols { flex-direction: column; gap: 10px; }
  .cal-pp-list { max-height: 42vh; }
  .cal-pp-right { max-height: 150px; }
}

/* ========== 小屏手机（≤480px） ========== */
@media (max-width: 480px) {
  .m-card-fields { grid-template-columns: 1fr; }
  .rep-chart-box { height: 240px; }
  th, td { font-size: 12px; }
  .m-card { padding: 10px 12px; }
  .content { padding: 10px 10px calc(128px + env(safe-area-inset-bottom, 0)); }   /* #321 随 ≤768 同步：底部固定批条留白 */
}

/* ---------- 暗色主题（双轨与 style.css 同构） ---------- */
[data-theme="dark"] .m-designer-hint { background: rgba(245, 158, 11, .14); color: #fcd34d; border-color: rgba(245, 158, 11, .35); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .m-designer-hint { background: rgba(245, 158, 11, .14); color: #fcd34d; border-color: rgba(245, 158, 11, .35); }
}
/* #265 门户手机端暗色补丁：pt-pinned 浅色底（PC 端欠账已由 #318 在 style.css 统一补齐） */
[data-theme="dark"] .pt-pinned,
[data-theme="dark"] .pt-pinned-tile { background: #141926; border-color: #1e2432; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pt-pinned,
  :root:not([data-theme="light"]) .pt-pinned-tile { background: #141926; border-color: #1e2432; }
}

/* ---------- 已安装为 APP（PWA standalone）----------
 * 从主屏图标打开后已是全屏应用，不再显示「存桌面」引导 */
@media (display-mode: standalone) {
  .tb-btn { display: none !important; }
}

/* #263 AI 悬浮球：上移避开底部 tab 栏（88px），弹窗层 z-index(50) 已高于球(40) 不再遮挡按钮 */
@media (max-width: 768px) {
  #lc_ai_float_btn {
    bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    right: 16px !important;
    width: 44px !important;
    height: 44px !important;
    font-size: 18px !important;
  }
  /* 2.0 #020 新增浮球：AI 球左侧（right 16+44+12=72px），同高避 Tab 栏；桌面 display:none */
  #lc_fab_add {
    display: block !important;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    right: 72px !important;
    width: 44px !important;
    height: 44px !important;
    font-size: 22px !important;
  }
  #lc_fab_add:active { transform: scale(.92); }
}

/* ---------- 2.0 #024 子表单竖排（手机端）：一行 N 列 → 每条记录一张卡片，
 字段逐行罗列（td::before 取 data-lbl 列名），「+ 添加行」加一条完整记录 = 添加 N 行输入。
 配套：lc-form-leaf.js 渲染与 lcAddSfRow 动态行均打 data-lbl；桌面端表格布局零变化 ---------- */
@media (max-width: 768px) {
  table.sf-edit-table { display: block; }
  table.sf-edit-table colgroup, table.sf-edit-table thead { display: none; }
  table.sf-edit-table tbody { display: block; }
  table.sf-edit-table tbody tr {
    display: block;
    margin: 0 0 10px;
    padding: 2px 12px 6px;
    border: 1px solid var(--c-border, #e8eaf0);
    border-radius: 10px;
    background: var(--c-card, #ffffff);
  }
  table.sf-edit-table tbody tr td {
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
    padding: 7px 0;
    overflow: visible;   /* 覆盖 sf-fixed-table 的 overflow:hidden */
  }
  table.sf-edit-table tbody tr td + td { border-top: 1px dashed var(--c-border, #e8eaf0); }
  table.sf-edit-table tbody tr td::before {
    content: attr(data-lbl);
    flex: 0 0 84px;
    font-size: 12px;
    color: var(--c-muted, #64748b);
    word-break: break-all;
  }
  /* 2.0 #031 输入控件占满余宽：不再按控件类型白名单枚举——td 直接子控件一律 flex:1。
     !important 压过两处来源：① lc-form-leaf 渲染的设计器列宽内联 style（width:XXpx）；
     ② style.css 的固定控件宽类（.sf-cell-number 100px / .sf-cell-money 120px 等）。
     此前白名单只覆盖 input/select/.src-picker/.lc-percent-wrap，其余类型控件
     （成员选择/日期/附件/金额大写等）保留固定宽 → 手机卡片右侧大片空白。 */
  table.sf-edit-table tbody tr td { width: 100% !important; }
  table.sf-edit-table tbody tr td > * { flex: 1 1 auto; width: auto !important; min-width: 0; }
  table.sf-edit-table tbody tr td > .btn { flex: 0 0 auto; width: auto !important; }
  /* 删除按钮行：右对齐、无标签、无分隔线 */
  table.sf-edit-table tbody tr td.sf-del-td { justify-content: flex-end; padding: 2px 0; border-top: 1px dashed var(--c-border, #e8eaf0); }
  table.sf-edit-table tbody tr td.sf-del-td::before { content: none; }
  table.sf-edit-table tbody tr td.sf-del-td .btn { flex: 0 0 auto; }
  /* 合计行：跟随卡片后的汇总条，只显示有合计的列，标签「列名 合计」 */
  table.sf-edit-table tfoot { display: block; }
  table.sf-edit-table tfoot tr {
    display: block;
    margin: -4px 0 10px;
    padding: 4px 12px;
    border: 1px dashed var(--c-border, #e8eaf0);
    border-radius: 10px;
  }
  table.sf-edit-table tfoot td { display: none; }
  table.sf-edit-table tfoot td.sf-sum-cell {
    display: flex;
    width: 100% !important;  /* 2.0 #031 压过设计器列宽内联 style */
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    font-size: 13px;
    font-weight: 600;
    color: #b45309;
  }
  table.sf-edit-table tfoot td.sf-sum-cell::before {
    content: attr(data-lbl) ' 合计';
    flex: 0 0 84px;
    font-size: 12px;
    font-weight: normal;
    color: var(--c-muted, #64748b);
  }
  /* 添加行按钮：全宽更易点 */
  table.sf-edit-table + .btn.ghost.sm { display: block; width: 100%; padding: 9px 0; margin-top: 2px; }
}

/* ===== 2.0 #040 审批流程条手机竖排（时间线；电脑保持横向，一个媒体查询两态共用）===== */
@media (max-width: 768px) {
  .fd-flow-sum { white-space: normal; line-height: 1.5; }
  .fd-flow-steps { flex-direction: column; gap: 0; }
  .fd-flow-step { flex: none; width: 100%; text-align: left;
    display: flex; flex-wrap: wrap; align-items: flex-start; column-gap: 10px;
    padding: 7px 0 7px 34px; position: relative; }
  .fd-flow-step::after {
    content: ''; position: absolute; left: 11px; top: 34px; bottom: -4px;
    width: 2px; height: auto; background: var(--c-border, #e8eaf0); }
  .fd-flow-step.done::after { background: #16a34a; }
  .fd-flow-step:last-child::after { display: none; }
  .fd-flow-dot { position: absolute; left: 0; top: 4px; }
  .fd-flow-name { flex: 1 1 55%; margin: 0; }
  .fd-flow-by { flex: 1 1 100%; margin: 2px 0 0; }
}
