/* ==========================================================================
   比亿办公系统 · 三端自适应覆盖层  bi-responsive.css
   --------------------------------------------------------------------------
   三档：
     · PC      ≥ 1024px  —— 本文件不生效，布局与你原来看到的**完全一致**
     · 平板    768–1023px —— 只压内边距与字号，结构不动
     · 手机    <  768px   —— 导航收汉堡、多栏改单列、宽表横向滑动、触控放大

   ★★ 铁律一：每一条规则都必须写在 `@media screen and (...)` 里 ★★
      打印 A4 时浏览器视口宽度 ≈ 794px，`@media (max-width:980px)` 会照样命中。
      少写一个 screen，送货单/合同/合格证就会被打歪——这是本项目最容易犯的错。

   ★★ 铁律二：不要碰 @media print 内的任何东西 ★★
      各页的打印样式是逐毫米调过的（A4 尺寸、页边距、分页），这里一条不改。

   ★★ 铁律三：不要给 .sheet / .a4-paper / .print-area 之类加 max-width:100% ★★
      单据纸张必须保持真实物理尺寸，手机上靠横向滑动看，压扁会导致打印比例错乱。
   ========================================================================== */

/* ---------- 0. 只在屏幕上生效的全局兜底 ---------- */

/* 汉堡按钮：默认（PC / 平板）不显示，只由 < 768px 那条媒体查询打开 */
.bi-nav-toggle { display: none; }

@media screen and (max-width: 1023px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  /* 弹窗在窄屏上不要超出屏幕 */
  .modal, .modal-dialog, .modal-box, .dialog { max-width: calc(100vw - 24px) !important; }
}

/* ---------- 1. 平板 768–1023：只收内边距 ---------- */
@media screen and (min-width: 768px) and (max-width: 1023px) {
  .top-nav-menu .nav-inner { padding-left: 14px !important; padding-right: 14px !important; }
  .top-nav-menu .nav-inner .nav-links a { padding: 6px 7px; font-size: 12.5px; }
  .wrap { padding-left: 14px !important; padding-right: 14px !important; }
  .container { padding-left: 14px !important; padding-right: 14px !important; }
}

/* ---------- 2. 手机 < 768：导航收成汉堡 ---------- */
@media screen and (max-width: 767px) {

  /* 2.1 顶栏：品牌 + 汉堡一行，菜单面板单独一行 ---------- */
  .top-nav-menu .nav-inner {
    position: relative;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: 56px !important;
    padding: 8px 12px !important;
  }
  /* 关键：basis 必须是 0，否则品牌名按自身宽度占位，
     长名字（如「比亿树脂办公系统-库存管理」）会把汉堡挤到第二行。 */
  .top-nav-menu .nav-inner .nav-lead {
    order: 1;
    flex: 1 1 0;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    overflow: hidden;
  }
  .top-nav-menu .nav-inner .nav-brand {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 15px;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* 品牌名文字节点本身也要能被截断（<a> 里是「图标 + 文本」） */
  .top-nav-menu .nav-inner .nav-brand .nav-name,
  .top-nav-menu .nav-inner .nav-brand > span:not(.nav-mark) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .top-nav-menu .nav-inner .nav-brand .nav-mark { width: 24px; height: 24px; flex: 0 0 auto; }
  /* 状态条在手机上只保留角色名，腾出横向空间 */
  .top-nav-menu .nav-inner .nav-user {
    height: auto;
    font-size: 11px;
    max-width: 34vw;
    overflow: hidden;
  }
  .top-nav-menu .nav-inner .nav-user .nav-user-text {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* 2.2 汉堡按钮 */
  .bi-nav-toggle {
    order: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    color: #334155;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .bi-nav-toggle:active { background: #eef2f7; }
  .bi-nav-toggle svg { width: 20px; height: 20px; }

  /* 2.3 菜单面板 */
  .top-nav-menu .nav-inner .nav-links {
    order: 3;
    display: none;
    width: 100%;
    margin: 0;
    padding: 4px 0 6px;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    max-height: 65vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid #e8edf3;
  }
  .top-nav-menu.bi-nav-open .nav-inner .nav-links { display: flex; }
  .top-nav-menu .nav-inner .nav-links a {
    justify-content: flex-start;
    padding: 12px 12px;
    font-size: 14.5px;
    line-height: 1.2;
    border-radius: 9px;
    white-space: normal;
  }
  .top-nav-menu .nav-inner .nav-links a svg { width: 18px; height: 18px; }
  .top-nav-menu .nav-inner .nav-links a.active { background: #165DFF; }
  /* 展开时给页面留出遮罩，点外部收起 */
  .bi-nav-scrim {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(15, 23, 42, .28);
  }

  /* 2.4 搜不到 .top-nav-menu 的页面（扫码端 / 我的销售）不注入汉堡，无需处理 */

  /* 2.5 主容器内边距收紧 */
  .wrap { padding: 12px 10px 48px !important; max-width: 100% !important; }
  .container { padding-left: 10px !important; padding-right: 10px !important; }
  main { padding-left: 10px; padding-right: 10px; }

  /* 2.6 多栏 → 单列（只针对明确的两栏容器类名） */
  .grid-2,
  .form-grid,
  .two-col,
  .split-2,
  .layout-2col,
  .main-split { display: block !important; }
  .grid-2 > *, .form-grid > *, .two-col > *, .split-2 > *, .layout-2col > *, .main-split > * {
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* 2.7 输入控件：字号 ≥16px 才不会让 iOS 聚焦时整页放大 */
  input, select, textarea {
    font-size: 16px !important;
    min-height: 40px;
  }
  textarea { min-height: 76px; }
  /* 按钮/小标签保持原字号，避免界面被撑爆 */
  button, .btn, .btn-primary, .btn-modal, input[type="checkbox"], input[type="radio"] {
    font-size: 14px;
    min-height: 0;
  }
  /* 复选框/单选框不要被拉到 40px 高 */
  input[type="checkbox"], input[type="radio"] { min-height: 0 !important; width: 18px; height: 18px; }

  /* 2.8 触控热区：可点元素至少 40px */
  .btn, .btn-modal, button.btn, .tab, .tabbar a, .tabbar button { min-height: 38px; }

  /* 2.9 表格：宽表在自己的容器里横滑，不顶破页面 */
  .tbl-scroll,
  .bi-tscroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .bi-tscroll > table { margin: 0; }
  /* 单元格不换行，让横滑真正有用（排除已是定宽的打印表格） */
  .bi-tscroll th, .bi-tscroll td { white-space: nowrap; }

  /* 2.10 图片/画布不出界（打印纸张类除外） */
  img:not(.sheet *):not(.print-area *) { max-width: 100%; height: auto; }

  /* 2.11 弹窗：贴边卡片式 */
  .modal > div,
  .modal-dialog,
  .modal-box {
    width: calc(100vw - 16px) !important;
    margin: 8px auto !important;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
  }
  .modal-header, .modal-body, .modal-footer { padding-left: 14px; padding-right: 14px; }

  /* 2.12 标签栏（库存等页）：横向滚动而不是换行堆叠 */
  .tabbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    white-space: nowrap;
    scrollbar-width: none;
  }
  .tabbar::-webkit-scrollbar { display: none; }
  .tabbar > * { flex: 0 0 auto; }

  /* 2.13 面板内边距收紧，手机上多挤出 20px 可用宽度 */
  .panel-head, .panel-header { padding: 10px 12px; }
  .panel-body { padding: 10px 12px; }
  .panel-body.flush { padding: 0; }
}

/* ---------- 3. 超窄屏 < 400：再收一档 ---------- */
@media screen and (max-width: 399px) {
  .top-nav-menu .nav-inner { padding: 7px 9px !important; }
  .top-nav-menu .nav-inner .nav-brand { font-size: 14px; }
  .wrap { padding: 10px 8px 40px !important; }
  .panel-head, .panel-header, .panel-body { padding-left: 9px; padding-right: 9px; }
}

/* ---------- 4. 安装为 App 后（standalone）安全区 ---------- */
@media screen and (display-mode: standalone) {
  .top-nav-menu .nav-inner {
    padding-top: calc(8px + env(safe-area-inset-top)) !important;
  }
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* ---------- 6. 单据类页面：浮动控制面板 + A4 纸张 ---------- */
@media screen and (max-width: 767px) {

  /* 6.1 合同 / 对账单 的「控制面板」「模板管理」是 position:fixed 悬浮在左右两侧，
      手机上一开会盖住正文（截图里两个面板直接叠在一起）。
      改成普通文档流：面板在上、单据在下，顺着滚就行，不再遮挡。 */
  .floating-panel,
  .template-panel,
  .style-panel,
  .export-panel,
  .control-panel,
  /* 对账单把「导出操作 / 模板管理 / 客户管理」装在 .management-container 里，
     这个容器自己是 position:fixed; right:20px; top:50%，光改子元素没用，必须改容器 */
  .management-container {
    position: static !important;
    transform: none !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    margin: 10px 0 !important;
    border-radius: 12px !important;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .08) !important;
    z-index: auto !important;
  }
  /* 容器改成 block 后，里面几个 280px 宽的面板要撑满 */
  .management-container > * {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 10px !important;
  }

  /* 6.2 对账单（body.bi-doc）的 A4 是 900px 版式，且内部大量绝对定位（公司名、公章、页脚）。
      **不能压成屏宽** —— 一压，绝对定位全部错位，公司名会被挤成一列竖排。
      这里恢复它 900px 的真实宽度，交给 .bi-pscroll 横向滑动（由 bi-responsive.js 套壳）。 */
  body.bi-doc .container {
    width: 900px !important;
    max-width: none !important;
    margin: 0 !important;
  }
  .bi-pscroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    width: 100%;
  }

  /* 6.3 送货单的 A4 预览：原本 max-width:100% 会把 784px 的版式压成 390px，
      表格列挤成竖排文字。这里保持真实宽度、让外层横向滑动。 */
  .delivery-preview-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start !important;
    max-width: 100% !important;
  }
  .delivery-preview-inner {
    width: 784px !important;
    max-width: none !important;
    transform: none !important;
    flex: 0 0 auto !important;
    margin: 0 !important;
  }

  /* 6.4 TDS 的 A4：页面自己在 480px 断点会压到 100%，这里统一压到屏宽并去掉多余留白，
      它是文档流排版，压窄只会换行、不会错位。 */
  .a4-page {
    width: 100% !important;
    min-height: auto !important;
    padding: 8mm 6mm !important;
    margin: 8px 0 !important;
    box-shadow: none !important;
  }
}
@media screen and (max-width: 767px) {
  .bi-pop-layer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: #fff;
    flex-direction: column;
  }
  .bi-pop-layer.bi-pop-open { display: flex; }
  .bi-pop-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: #165DFF;
    color: #fff;
    font-size: 15px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .18);
  }
  .bi-pop-close {
    border: 1px solid rgba(255, 255, 255, .55);
    background: rgba(255, 255, 255, .16);
    color: #fff;
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 14px;
    min-height: 34px;
  }
  .bi-pop-frame {
    flex: 1 1 auto;
    width: 100%;
    border: 0;
    background: #fff;
  }
}
