/* ============================================================
   styles-mobile.css · 手机浏览器适配

   策略：不重写页面，只改布局。
     桌面端的 16 个页面和它们的逻辑一行不动，
     这里通过媒体查询把「左侧固定栏 + 右侧内容」换成
     「顶部标题 + 抽屉导航 + 全宽内容」。

   为什么这么选：
     另写一套移动端页面 = 两套代码两套 bug。
     审批页 578 行，业务逻辑（三段式、页签、自我批准提示）
     复制一份就意味着以后改一处要改两处，
     迟早不一致。布局问题就该用布局解决。

   断点 860px：
     再宽就不像手机了，平板横屏也能用桌面布局。
   ============================================================ */

@media (max-width: 860px) {

  /* ---------- 整体：单列 ---------- */
  #app {
    grid-template-columns: 1fr;
    height: 100vh;
    /* 手机浏览器地址栏会吃掉高度，用 dvh 避免内容被顶出屏幕 */
    height: 100dvh;
  }

  /* ---------- 侧栏变成抽屉 ---------- */
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
    padding-top: 54px;      /* 让开顶栏 */
    box-shadow: none;
    will-change: transform;
  }
  #sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0,0,0,.14);
  }

  /* 抽屉打开时的遮罩 */
  #sb-mask {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.32);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
  }
  #sb-mask.on {
    opacity: 1;
    pointer-events: auto;
  }

  /* ---------- 顶栏 ---------- */
  #m-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    background: rgba(255,255,255,.94);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
  }
  #m-topbar .m-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -.01em;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #m-topbar .m-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border: 0; background: transparent;
    font-size: 19px; line-height: 1;
    color: #333; border-radius: 8px;
    flex: none;
  }
  #m-topbar .m-btn:active { background: #f0f0f0; }
  #m-topbar .m-count {
    position: absolute; top: 6px; right: 6px;
    min-width: 16px; height: 16px;
    background: var(--warnbd, #b26a00); color: #fff;
    border-radius: 8px; font-size: 10px; line-height: 16px;
    text-align: center; padding: 0 4px;
  }

  /* ---------- 内容区 ---------- */
  #main {
    padding: 52px 0 0 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* 底部状态条是贴底的通栏（高约 36px），
     内容区留出对应空间，否则最后一行永远被压住。 */
  #page { padding: 14px 14px calc(36px + 20px); }

  /* ---------- 数据服务指示器 ----------
     桌面端是右下角常驻的浮动条。手机上它一直挡住内容 ——
     390px 宽的屏幕，浮动条正好压住最后一行。

     手机上改成「贴在顶栏下方的一条细状态」，不遮挡正文：
     用户需要知道的只是「连没连上」，不需要一直看到退出按钮。 */
  #mode-ind {
    position: fixed !important;
    top: auto !important;
    right: auto !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: none !important;
    border-radius: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    border-bottom: 0 !important;
    padding: 6px 12px !important;
    font-size: 11.5px !important;
    box-shadow: 0 -1px 6px rgba(0,0,0,.05) !important;
    z-index: 45;   /* 低于顶栏 50，高于内容 */
    justify-content: flex-start;
  }
  #mode-ind button { min-height: 30px !important; padding: 3px 10px !important; font-size: 12px !important; }

  /* ---------- 触控尺寸 ----------
     iOS 建议最小 44px。桌面端的 28px 按钮在手机上很难点准。 */
  button {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 14px;
    border-radius: 8px;
  }
  button.sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
  input, select, textarea {
    min-height: 40px;
    font-size: 16px;   /* 小于 16px 时 iOS 会自动放大页面，很难受 */
    border-radius: 8px;
  }

  /* ---------- 表格：改成卡片式 ----------
     横向滚动的表格在手机上基本没法用。
     每个 tr 变成一块，td 用 data-label 显示字段名。 */
  table { display: block; }
  thead { display: none; }
  tbody, tr, td { display: block; width: auto; }
  tbody tr {
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 12px 14px;
    background: #fff;
  }
  /* 竖排而不是左右分栏。
     左右分栏时字段名固定占 76px，值区只剩 200 多 px，
     邮箱（matthew@hubbl.co.uk 约 140px）加上前缀姓名就放不下，
     浏览器只能从中间硬断。

     竖排之后值独占整行宽度，邮箱基本都能一行放下。 */
  tbody td {
    border: 0 !important;
    padding: 6px 0 3px !important;
    text-align: left !important;
    display: block;
    font-size: 13.5px;
    min-width: 0;
  }
  tbody td::before {
    content: attr(data-label);
    display: block;
    color: var(--faint);
    font-size: 11.5px;
    margin-bottom: 2px;
    letter-spacing: .02em;
  }
  tbody td > * {
    min-width: 0;
    overflow-wrap: break-word;
    word-break: normal;
  }
  tbody td:empty { display: none; }

  /* ---------- 卡片网格 ----------
     指标卡（.cards）双列，信息类卡片（审批列表）单列。
     审批卡片两列在手机上太窄：标题换行、按钮挤在一起，
     而且每张卡有 10 个信息维度，两列根本放不下。 */
  .cards {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }
  .cards.c4 { grid-template-columns: 1fr 1fr !important; }

  /* 审批列表：单列。每张卡有 10 个信息维度，
     两列在 390px 屏上标题要换行、按钮挤成一团。 */
  .approval-list {
    grid-template-columns: 1fr !important;
  }
  .cards.c2 { grid-template-columns: 1fr !important; }

  /* ---------- 邮箱、长文本 ----------
     桌面端用 ellipsis 截断，手机上截断就看不全了 ——
     审批时最需要看的就是邮箱地址，截了等于没法核对。 */
  /* 邮箱这类长字符串：优先在 @ 前后断，不要从中间劈开。
     break-all 会把 matthew@hubbl.co.uk 拆成 "matthew@hubbl.c / o.uk"，
     审批时要核对邮箱，看着很别扭。 */
  /* 邮箱字号再小一号：matthew@hubbl.co.uk 在 390px 屏上
     11px 时约 118px 宽，配合竖排布局基本能一行放下。 */
  td .mono[style*="font-size:11px"],
  td .mono {
    font-size: 11.5px !important;
    line-height: 1.5;
    white-space: normal !important;
    /* 邮箱用 break-word 不用 anywhere ——
       anywhere 会从任意字符断开（matthe / w@hubb / l.co.u / k），
       完全没法读。break-word 只在整词放不下时才断，
       配合 <wbr> 能让它优先在 @ 和 . 处折行。 */
    overflow-wrap: break-word;
    word-break: normal;
    max-width: 100%;
  }
  /* <wbr> 是浏览器原生的建议断点，不需要额外样式，
     但父元素必须是正常断词模式（见上面的 word-break:normal）。 */
  .ellipsis { white-space: normal !important; overflow: visible !important; text-overflow: clip !important; }

  /* ---------- 审批页的页签：横向滚 ----------
     页签在手机上要能横向滑动 —— 竖排会占掉半屏。
     这里单独允许横向滚动，其它地方一律不要滑条。 */
  .sheet-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sheet-tabs::-webkit-scrollbar { display: none; }
  .ctab { padding: 8px 14px; font-size: 13px; }

  /* ---------- 弹窗全屏 ---------- */
  .modal, .drawer {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
  }

  /* ---------- 其它 ---------- */
  h1 { font-size: 19px !important; }
  h2 { font-size: 16px !important; }
  .pagehd { flex-direction: column; align-items: stretch !important; gap: 10px; }
  .row { flex-wrap: wrap; }
}

/* ---------- 隐藏桌面专属元素 ---------- */
@media (min-width: 861px) {
  #m-topbar, #sb-mask { display: none !important; }
}

/* 触屏设备去掉 hover 效果（点完会残留高亮） */
@media (hover: none) {
  button:hover { background: #fff; }
  .nav a:hover { background: transparent; }
}
