/* ============================================================
   方汀一体化管理系统 · 手机端统一排版优化
   加载位置：各页面内联 style 之后（优先级高于页面原样式）
   适用断点：≤768px（手机） / ≤480px（小屏）
   只做排版与触控适配，不改动任何业务逻辑
   ============================================================ */

@media (max-width: 768px) {
  html { -webkit-text-size-adjust: 100%; }

  /* ---------- 0. 移动端字阶基准（v3 §2 的移动端口径）----------
     桌面端不受影响：这一整块只在 ≤768px 生效。
     起因（2026-11-02，8 角色 QA 报告 7 人同一条）：手机上正文 13px、表格 12.5px，
     一线在车间举着手机看，13px 是真看不清。桌面 13px 是 v3 的 L7，合规；手机要单独抬。
       正文 16px │ 表格数据 14px │ 控件 16px（防 iOS 聚焦放大）│ 辅助与元信息 ≥13px
     v3 的 L8（12px）只留给单位、角标、页脚，不再用于说明性正文行。 */
  body { font-size: 16px; line-height: 1.6; }

  /* 正文载体：16px。只列"读一句话"的元素，不碰控件与表格（各有着色规则） */
  p, li, dd, dt, blockquote,
  .desc, .card-desc, .section-desc, .note, .note-line, .alert, .failing, .fail,
  .empty, .empty-text, .hint, .tip, .msg, .help-text, .form-help { font-size: 16px; }

  /* 页标题：手机上 13px 的 h1 比正文还小，层级全乱 */
  h1 { font-size: 18px; }
  h2 { font-size: 17px; }

  /* 辅助与元信息：不低于 13px（原 11~12px） */
  small, .sub, .meta, .stat-label, .kpi-label, .kpi-k, .kpi-s, .subnav-meta, .tag, .badge, .bdg,
  .alert-sum, .count-line, .fresh, .mut-line,
  /* 表单标签：v3 §5.6 是 13px，桌面写 12px 的页面在手机上跟着这条走 */
  label, .form-item label, .form-group label, .form-row label, .field-label,
  .label, .card .sub, .card .label, .dist-row, .alert-empty { font-size: 13px; }

  /* 面板小标题与"看全部"链接：14px（原 12~13px，手指点也偏小） */
  .dist-title, .panel-title, .sec-more, .entry-desc { font-size: 14px; }
  /* 卡片标题下的副行说明：13px（页内 `.section .sub` 带前缀，权重更高，这里补同权重） */
  .section .sub, .card-title .sub, .card-head .sub { font-size: 13px; }
  /* 登录页辅助行：11~12px 在 375 屏上是真看不清 */
  .login-tip { font-size: 13px; }
  .login-support, .login-logo p { font-size: 13px; }

  /* ---------- 1. 顶部栏：消除标题折行、用户名竖排 ---------- */
  .header { height: auto !important; min-height: 54px; padding: 8px 12px !important; gap: 8px; }
  .header .logo, .header .header-left, .header > div:first-child { gap: 8px; min-width: 0; flex: 1 1 auto; }
  .logo img, .logo-svg, .header-left img, .header > img { width: 32px !important; height: 32px !important; }
  .header h1, .logo h1, .logo-text h1, .header-left h1 {
    font-size: 15px !important; line-height: 1.3 !important;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: 0 !important;
  }
  .header p, .logo p, .logo-text p, .header-left p { display: none !important; }
  .header-right { gap: 6px; flex-shrink: 0; }
  /* AI 助手按钮窄屏只留图标（全站暂无页面使用 .ai-btn-top，此规则仅作兜底） */
  .ai-btn-top { font-size: 0 !important; padding: 8px 10px !important; line-height: 1; }
  /* 规范 v3 §10 禁 emoji 当功能图标：改纯文字 */
  .ai-btn-top::before { content: "AI"; font-size: 14px; font-weight: 600; }
  /* 用户名文字隐藏（头像与退出保留） */
  .user-info span, .user-info #currentUserName { display: none !important; }
  .user-info { gap: 6px; }
  .user-avatar { width: 30px !important; height: 30px !important; font-size: 13px !important; }
  .logout-btn, .back-btn, .back, .back-link { white-space: nowrap !important; padding: 7px 11px !important; font-size: 14px !important; }

  /* ---------- 2. 标签页 / 导航条：横向滚动，禁止文字折行 ---------- */
  /* 注意：不含 .nav —— 西赛库房的 .nav 在自己样式里是 display:none（改为汉堡菜单），不能覆盖 */
  .tabs, .nav-tabs, .mode-tabs, .tab-bar {
    display: flex !important; flex-wrap: nowrap !important;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; -ms-overflow-style: none;
  }
  .tabs::-webkit-scrollbar, .nav-tabs::-webkit-scrollbar,
  .mode-tabs::-webkit-scrollbar, .tab-bar::-webkit-scrollbar { display: none; }
  .tab, .nav-tab, .mode-tab, .tab-item {
    flex: 0 0 auto !important; white-space: nowrap !important;
    /* 左右 12（不是 14）：375 屏上 4 个页签要能一眼看全（v2 判据 5：一级入口不用横滑） */
    padding: 9px 12px !important; font-size: 14px !important;
    min-height: 44px; display: flex; align-items: center;
  }

  /* ---------- 3. 表格：容器内横向滚动，不再撑破页面 ---------- */
  .card, .section, .panel, .tab-content, .table-responsive, .table-wrap {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  /* 表格数据 14px（原 12.5px）。手机上表格的合法形态是「容器横向滚动」，
     不是把列压窄或删列——所以 14px 与 nowrap 同时保留，交给容器去滚。 */
  table { font-size: 14px; }
  th, td { padding: 9px 10px !important; white-space: nowrap; font-size: 14px; }
  .info-table td, .data-table td { white-space: normal; }
  /* 空态整表替换（tbody 里放 .empty）时取消表格最小宽度：
     否则表格仍按 min-width:600px 撑开、空态文案按 600px 居中，
     首屏只能看到左半边（实测采购页「暂无采购申请」被裁成「暂无采购申」） */
  table:has(tbody .empty), table:has(td > .empty) { min-width: 0 !important; }

  /* ---------- 4. 卡片标题栏：标题与按钮分行，按钮更好按 ---------- */
  .card-title, .page-header, .toolbar, .section-title { flex-wrap: wrap; gap: 10px; }
  .card-title { align-items: flex-start !important; }
  /* 卡片标题里的按钮各占一行，避免长按钮文字折行 */
  .card-title > .btn, .card-title > button { flex: 1 1 100% !important; min-height: 44px; }
  /* 按钮外面还包了一层内联 flex 容器时，让那层也变成竖排 */
  .card-title > div[style*="display:flex"], .card-title > div[style*="display: flex"] {
    flex-direction: column !important; gap: 8px !important; width: 100% !important;
  }
  .card-title > div[style*="display:flex"] > .btn,
  .card-title > div[style*="display: flex"] > .btn { width: 100% !important; min-height: 44px; }
  /* 工具条按钮保持并排 */
  .toolbar > .btn, .toolbar > button { flex: 1 1 auto; min-height: 44px; }

  /* ---------- 5. 触控尺寸：按钮/输入框一律 44px 高（v3 §7 移动端口径） ---------- */
  /* 桌面按钮 32px 是 v3 §5.5 的规定，但那条在桌面媒体查询里，本块不碰它 */
  .btn, button.btn, .btn-sm, .btn-exp, .search-btn, .ask-btn,
  .btn-primary, .btn-secondary, .btn-danger, .btn-text, .btn-accent {
    padding: 10px 14px; font-size: 14px; min-height: 44px;
  }
  .btn-sm, .btn-secondary.btn-sm { min-height: 44px; min-width: 44px; padding: 8px 12px; }
  /* 表格/列表行内操作按钮：44×44（v3 §7「表格行内操作按钮 ≥44px」）。
     原先是 40px 高、宽度跟着文字走，戴手套点「修改」经常点到隔壁「删除」。 */
  td .btn, td button, .row-actions .btn, .row-actions button,
  .table-actions .btn, .table-actions button, .act-btns .btn, .act-btns button {
    min-height: 44px; min-width: 44px;
    display: inline-flex; align-items: center; justify-content: center;
  }
  input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
    font-size: 16px !important; min-height: 44px;
  }
  /* 文件框单独补：前一条把它排除，是因为原生 file 控件在部分浏览器里强加 min-height
     会出现一条空白轨道（视觉怪）。但"样式怪"不等于"可达性可以不管"：
       - font-size 必须给：iOS Safari 里输入类控件字号 <16px，聚焦时会把整页放大，
         file 框同样中招（原生按钮文字也是输入类字号）；
       - 44px 是触控目标下限，手指点「选择文件」和点按钮是同一回事。
     ⚠️ quality.html 里有一条同口径的页面级兜底（qc-seat 697c715 加的），两条重叠无害。
       清理 CSS 时删任一条，都要先确认另一条还在。 */
  input[type="file"] { font-size: 16px !important; min-height: 44px; }
  .form-control { font-size: 16px !important; min-height: 44px; padding: 10px 12px; }
  .form-row, .form-row-3, .form-grid { grid-template-columns: 1fr !important; }

  /* ---------- 6. 悬浮按钮：缩小 + 底部留白，不再压住正文 ---------- */
  .ai-fab {
    width: 50px !important; height: 50px !important; font-size: 22px !important;
    right: 14px !important; bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    opacity: .92;
  }
  body:has(.ai-fab) { padding-bottom: 88px; }

  /* ---------- 7. 弹窗：铺满窄屏，底部按钮分行 ---------- */
  /* 注意：.modal 在不同页面里身份相反：
       主系统页是「遮罩 > 对话框」——.modal-overlay/.mask 是遮罩，.modal 是对话框；
       西赛页是「.modal 当遮罩 > .modal-content 当对话框」。
     若笼统给 .modal 定宽，西赛的全屏遮罩会被缩窄。所以只精确命中对话框本体。 */
  .modal-overlay > .modal, .mask > .modal, .modal > .modal-content {
    /* 原写法 width:100% + margin:8px：对话框 375 宽 + 两侧各 8px = 必超视口 8px（实测西赛 10 个弹窗全中） */
    width: calc(100% - 16px) !important; max-width: calc(100% - 16px) !important;
    max-height: 90vh; border-radius: 14px !important; margin: 8px;
  }
  .modal-header { padding: 14px 16px !important; }
  .modal-body { padding: 14px 16px !important; }
  .modal-footer { flex-wrap: wrap; gap: 8px; padding: 12px 16px !important; }
  .modal-footer .btn { flex: 1 1 100%; min-height: 44px; }
  /* 关闭按钮（×）：西赛实测仅 13×26，手机上点不中 */
  .modal-close {
    min-width: 36px !important; min-height: 36px !important;
    display: inline-flex !important; align-items: center; justify-content: center;
    font-size: 24px !important;
  }

  /* ---------- 8. 网格：两列卡片，基地单列 ---------- */
  .stats-grid, .stats-row { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .modules-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .bases-grid, .base-grid { grid-template-columns: 1fr !important; }
  .main, .container { padding: 12px !important; }
  .card, .section { padding: 14px !important; }
}

/* ---------- 小屏（≤480px）再收紧一档 ---------- */
@media (max-width: 480px) {
  .header h1, .logo h1, .logo-text h1, .header-left h1 { font-size: 14px !important; }
  .module-card, .base-card, .stat-card { padding: 14px !important; }
  .module-icon { width: 44px !important; height: 44px !important; font-size: 22px !important; margin-bottom: 10px !important; }
  .module-name { font-size: 15px !important; }
  .module-desc { font-size: 12px !important; }
  .welcome-banner { padding: 16px 18px !important; }
  .welcome-text h2 { font-size: 18px !important; }
  .stat-value { font-size: 20px !important; }
  .section-title { font-size: 15px !important; margin: 20px 0 12px !important; }
  .footer { padding: 20px 12px !important; }
}

/* ---------- 登录页：压缩卡片高度，让键盘弹起后登录按钮仍在可视区内 ---------- */
@media (max-width: 768px) {
  .login-overlay { padding: 16px 10px !important; align-items: flex-start !important; }
  .login-card { padding: 24px 20px !important; margin: auto !important; max-width: 100% !important; border-radius: 14px; }
  .login-logo { margin-bottom: 14px !important; }
  .login-logo img { width: 52px !important; height: 52px !important; }
  .login-logo h2 { font-size: 18px !important; margin-top: 8px !important; }
  .login-form .form-group { margin-bottom: 12px !important; }
  .login-btn { padding: 13px !important; font-size: 16px !important; }
  .login-tip { margin-top: 12px !important; }
}

/* 矮视口（≈软键盘弹起后）：再精简一层，让登录按钮直接落在首屏，不用滚 */
@media (max-width: 768px) and (max-height: 460px) {
  .login-overlay { padding: 10px 8px !important; align-items: flex-start !important; }
  .login-card { padding: 18px 18px !important; }
  .login-logo { margin-bottom: 8px !important; }
  .login-logo img { display: none !important; }
  .login-logo h2 { font-size: 16px !important; margin-top: 0 !important; }
  .login-form .form-group { margin-bottom: 8px !important; }
  .login-form label { margin-bottom: 4px !important; }
  .login-btn { padding: 11px !important; margin-top: 4px !important; }
  .login-tip { display: none !important; }
  .login-support { display: none !important; }
}

/* ---------- 9. AI 助手面板（手机端） ---------- */
/* 原写法是「固定高 520px + bottom 80px」：视口一变矮（软键盘弹起、小屏手机）
   面板顶部就被裁掉，标题和对话内容看不见。改为上下同时定位，高度自动跟随视口：
     · Android：软键盘弹起会压缩视口，面板自己就跟着变矮
     · iOS：视口不变、键盘盖在下面，靠 JS 写入的 --kbh（键盘高度）把底边顶上去
   两条路都不再用固定高度，就不会被裁。
------------------------------------------------------------------ */
/* 遮罩：手机端 AI 面板以外的区域压暗一层，点一下就关面板。
   桌面端不显示（display:none），完全不影响电脑上的使用。 */
.ai-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 30, 45, .35); z-index: 155;
}

@media (max-width: 768px) {
  .ai-backdrop.show { display: block; }
  body.ai-open { overflow: hidden; }
  /* 悬浮按钮浮在遮罩之上，保持明亮、可直接点关 */
  .ai-fab { z-index: 165 !important; }
  .ai-panel {
    position: fixed !important;
    left: 10px !important; right: 10px !important;
    top: 24px !important;
    width: auto !important; height: auto !important; max-height: none !important;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px) + var(--kbh, 0px)) !important;
    border-radius: 16px !important;
    box-shadow: 0 14px 44px rgba(0, 0, 0, .32) !important;
  }
  .ai-header { padding: 11px 14px !important; }
  .ai-header-title .row1 { font-size: 14px !important; }
  .ai-sub { font-size: 11px !important; }
  .ai-close { width: 36px !important; height: 36px !important; font-size: 24px !important; }
  .ai-messages { padding: 12px !important; -webkit-overflow-scrolling: touch; }
  .ai-msg { margin-bottom: 12px !important; gap: 7px !important; }
  .ai-avatar { width: 28px !important; height: 28px !important; font-size: 14px !important; }
  /* 气泡放宽到 86%：原来 78% 在手机上每行只放得下十来个字，回答要多滚好几屏 */
  .ai-bubble { max-width: 86% !important; font-size: 14px !important; line-height: 1.8 !important; padding: 11px 13px !important; overflow-wrap: anywhere; }
  /* AI 回答里的 Markdown 表格必须能换行：上面给数据表加的 th,td{white-space:nowrap}
     会连带命中气泡内的表格，把表格撑到 358px 塞进 256px 的气泡里、整条答案横向溢出。
     这里显式还原为 normal，并允许长串（URL/参数）任意断行。 */
  .ai-bubble table { font-size: 12px !important; table-layout: fixed !important; width: 100% !important; }
  .ai-bubble th, .ai-bubble td {
    white-space: normal !important;
    padding: 6px 8px !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }
  /* 命令/代码块：手机上自动换行（横滑不好操作），超长串仍可滚 */
  .ai-bubble pre {
    margin: 7px 0; padding: 8px 10px; background: #f2f5f9;
    border-radius: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch;
    font-size: 12.5px; line-height: 1.6;
    white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
    max-width: 100%;
  }
  /* 快捷问题改单行横向滚动：原来 7 个按钮换行堆了 96px，吃掉近两成面板高度 */
  .ai-quick {
    flex-wrap: nowrap !important; overflow-x: auto;
    max-height: none !important; padding: 8px 10px !important;
    scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch;
  }
  .ai-quick::-webkit-scrollbar { display: none; }
  .ai-quick-btn {
    flex: 0 0 auto !important; white-space: nowrap !important;
    min-height: 34px; padding: 7px 13px !important;
    display: inline-flex; align-items: center;
  }
  .ai-input-area { padding: 10px !important; gap: 8px !important; }
  /* 16px 字号：小于 16px 时 iOS 聚焦输入框会自动放大整个页面 */
  .ai-input { font-size: 16px !important; min-height: 44px !important; padding: 10px 12px !important; }
  .ai-send { width: 44px !important; height: 44px !important; flex: 0 0 44px !important; font-size: 18px !important; border-radius: 12px !important; }
}

/* ---------- 10. 触控目标补齐（实测 390×844 下小于 40px 的可点元素） ---------- */
@media (max-width: 768px) {
  /* 返回主系统 / 退出：实测只有 30~32px 高 */
  .back, .back-btn, .back-link, .header .back, .header .back-btn, .logout-btn {
    min-height: 44px !important;
    padding: 8px 14px !important;
    /* 不强制 display:inline-flex：西赛页在手机端有意把「退出」收进汉堡菜单
       （页内 .logout-btn{display:none}），这里若强制 display 会把它拽回顶栏、
       和「主系统」按钮挤成一团；min-height 对块级/弹性盒子同样生效 */
  }
  /* 知识库热门标签：实测 78×30 */
  .hot-tag { min-height: 44px; display: inline-flex; align-items: center; padding: 8px 16px !important; font-size: 14px !important; }
  /* 工艺页顶部导航项：实测 37px 高 */
  .nav-item { min-height: 44px; display: flex; align-items: center; }
  /* 西赛汉堡菜单：实测只有 20×30，手机上很难点中 */
  .menu-toggle {
    min-width: 44px !important; min-height: 44px !important; font-size: 24px !important;
    display: inline-flex !important; align-items: center; justify-content: center;
  }
  /* 正文里的外链（如「百度智能云」） */
  li a, p a, td a { min-height: 44px; display: inline-flex; align-items: center; }
  /* 顶栏 AI 助手按钮 */
  .ai-btn-top { min-height: 44px !important; }
}

/* ---------- 手机端触控目标：小于 40px 的按钮加大，避免手指点不准 ---------- */
@media (max-width: 768px) {
  /* 收发看板的「今日/本月/全部」范围切换 */
  .chart-range button { min-height: 44px !important; padding: 8px 14px !important; font-size: 14px !important; }
  /* 西赛顶栏「主系统」：padding 加大后必须禁折行，否则「主系统」竖排成两行 */
  .home-btn { min-height: 44px !important; padding: 8px 14px !important; font-size: 14px !important; white-space: nowrap !important; }
  /* 正文说明里的外链（如"百度智能云"），手机上很难点中，加大点击区 */
  li a, p a, td a { display: inline-block; padding: 6px 2px !important; }
}

/* ---------- 11. 单选/复选：原生 13×13 点不准（实测设置页 aiEnabledOn/Off、ocrEnabled） ---------- */
@media (max-width: 768px) {
  input[type=radio], input[type=checkbox] { width: 20px !important; height: 20px !important; flex: 0 0 auto; }
  /* 控件外面包的 label 才是真点击区（label[style*=cursor:pointer] 包 input 的标准可达性写法）：
     原生 13×13 不动，把 label 垫到 40px 高 + 水平留白，手指落点 = 整个 label */
  label:has(> input[type=radio]), label:has(> input[type=checkbox]),
  label:has(input[type=radio]), label:has(input[type=checkbox]) {
    /* display 交给页面自己的内联样式；对没写 display 的补 inline-flex，
       否则纯 inline 的 label 上 min-height 不生效、点击区还是矮的 */
    display: inline-flex; align-items: center;
    min-height: 44px; padding: 6px 10px;
  }
}

/* ---------- 12. 字号下限 13px（手机口径；桌面 v3 §17 的 12px 下限不在此块内） ---------- */
@media (max-width: 768px) {
  /* 首页各库房分布的「N 种 · 今日 x/y」（--fs-9=11px） */
  .dist-more, .go, #sysEntry { font-size: 13px !important; }
  /* 西赛流水时间戳等 <small>：浏览器默认 smaller ≈ 10.8px */
  small { font-size: 13px; }
  /* 设置页权限细分矩阵：角色名 admin/keeper…、「已授予/已关闭/全权」内联 11px，
     「仅限管理员/部分限管理员」徽标内联 var(--fs-9)=11px */
  #permBody [style*="font-size:11px"], #permBody [style*="font-size:var(--fs-9)"] { font-size: 13px !important; }
}

/* ---------- 13. 文字链接类触控目标 ---------- */
@media (max-width: 768px) {
  /* 首页「需要处理」里的系统设置链接：实测 52×24 */
  .sys-link { min-height: 44px; display: inline-flex; align-items: center; padding: 4px 6px !important; }
  /* 西赛库管员操作卡头部：标题可折行，「收起/展开」不许被挤成竖排、加大点击区 */
  .kg-head span:last-child { flex: 0 0 auto; white-space: nowrap; min-height: 36px; display: inline-flex; align-items: center; }
  /* 西赛顶栏：logo 文字（库房名）与右侧库房下拉完全同义，手机上二选一。
     375px 放不下「库房名 + 刚刚更新 + 库房下拉 + 主系统 + 汉堡菜单」五件套：
     收缩它会被「刚刚更新」chip 盖住后半截，不收缩又把汉堡菜单按钮顶出屏外（实测 scrollW=401）。
     所以手机上收起这段重复文字，库房名以下拉为准。 */
  .logo:has(#whTitle) { display: none !important; }
}
