/* 独立新增：手机 H5 适配（不修改 app.css 的任何既有规则）。
 * 目标：拇指可达的底部导航、卡片化表格、iOS 安全区、16px 输入防缩放、横屏可用。 */
:root { --h5-nav-h: 58px; --h5-safe-b: env(safe-area-inset-bottom, 0px); }

@media (max-width: 820px) {
  html { -webkit-text-size-adjust: 100%; }
  body { padding-bottom: calc(var(--h5-nav-h) + var(--h5-safe-b) + 12px); }

  /* 桌面侧栏在手机上完全隐藏，导航交给底部 H5 栏 */
  .app > .sidebar { display: none !important; }
  .main { width: 100%; }
  .banner {
    position: sticky; top: 0; z-index: 30;
    min-height: 76px; padding: 10px 12px;
    border-radius: 0 0 14px 14px;
  }
  .banner-copy h1 { font-size: 17px; line-height: 1.2; }
  .banner-copy p { font-size: 11px; margin-top: 2px; }
  .banner-user { gap: 6px; }
  .banner-user .who span { display: none; }
  .content { padding: 10px 10px 16px; }

  /* 卡片：更大点击面积、更清楚的层级 */
  .page .card { border-radius: 12px; padding: 12px; margin-bottom: 10px; box-shadow: 0 2px 10px rgba(20,14,13,.05); }
  .page-hd { padding: 4px 2px 8px; gap: 6px; }
  .page-hd h2 { font-size: 18px; }
  .page-hd .tag { font-size: 10px; padding: 3px 6px; }
  .card-hd h3, .qa-card-hd b { font-size: 14px; }
  .statrow, .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  .statrow .card, .kpis .card { min-width: 0; }
  .statrow .card b, .kpi-num { font-size: 17px !important; }
  .statrow .card span { font-size: 11px; }

  /* 输入与按钮：iOS 不会自动放大，触摸目标不小于 40px */
  input, select, textarea { font-size: 16px !important; max-width: 100%; }
  button, .linkish, .switch, .tabs button {
    min-height: 38px; padding: 8px 12px; -webkit-tap-highlight-color: transparent;
  }
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; max-width: 100%; }
  .tabs button { white-space: nowrap; flex: 0 0 auto; }
  .tools { gap: 6px; }

  /* 表格：保留横向滚动能力；JS 会把关键表格转成卡片 */
  .page table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.h5-cards { display: block; overflow: visible; }
  table.h5-cards thead { display: none; }
  table.h5-cards tbody { display: block; }
  table.h5-cards tbody tr {
    display: block; padding: 9px 10px; margin-bottom: 8px; border: 1px solid #eceae7;
    border-radius: 9px; background: #fff;
  }
  table.h5-cards tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 5px 0 !important; border: 0 !important; text-align: right !important;
    font-size: 12px; min-width: 0;
  }
  table.h5-cards tbody td::before {
    content: attr(data-label); flex: 0 0 auto; color: #8a8a8f; font-size: 11px; text-align: left;
  }
  table.h5-cards tbody td:first-child { font-weight: 600; font-size: 13px; }
  table.h5-cards tbody td:empty { display: none; }
  .h5-scroll-hint { color: #aaa; font-size: 10px; margin-top: 4px; }

  /* SVG 图表：保持比例，避免溢出 */
  svg { max-width: 100%; height: auto; }
  .heatmap, .metrics-grid, .rg-signals, .qa-sector, .eng-pipeline { grid-template-columns: 1fr !important; }

  /* 弹层：从底部升起，手势区更大 */
  .qa-modal, .modal, .drawer {
    width: 100vw !important; max-width: 100vw !important;
    max-height: 86vh; overflow-y: auto; border-radius: 16px 16px 0 0 !important;
    padding-bottom: calc(20px + var(--h5-safe-b));
  }
  .drawer-mask, .modal-mask, .qa-mask { align-items: flex-end !important; }
  .toast { left: 12px !important; right: 12px; bottom: calc(var(--h5-nav-h) + var(--h5-safe-b) + 12px) !important; text-align: center; }

  /* 底部导航 */
  .h5-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
    height: calc(var(--h5-nav-h) + var(--h5-safe-b));
    padding-bottom: var(--h5-safe-b);
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: rgba(255,255,255,.97); border-top: 1px solid #e8e6e3;
    box-shadow: 0 -2px 14px rgba(20,14,13,.06);
    backdrop-filter: blur(8px);
  }
  .h5-nav a {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: #8b8b90; font-size: 10px; text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  .h5-nav a svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
  .h5-nav a.on { color: #e10600; font-weight: 600; }
  .h5-nav a.on svg { stroke-width: 2.2; }
  .h5-nav a .h5-dot { position: absolute; top: 6px; margin-left: 20px; width: 5px; height: 5px; border-radius: 50%; background: #e10600; }

  .h5-sheet {
    position: fixed; inset: 0; z-index: 120; background: rgba(10,8,8,.45);
    display: none; align-items: flex-end;
  }
  .h5-sheet.on { display: flex; }
  .h5-sheet-body {
    width: 100%; max-height: 72vh; overflow-y: auto; background: #fff;
    border-radius: 18px 18px 0 0; padding: 16px 14px calc(20px + var(--h5-safe-b));
  }
  .h5-sheet h4 { margin: 0 0 12px; font-size: 15px; }
  .h5-sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
  .h5-sheet-grid a {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 10px 4px; background: #f7f6f4; border-radius: 10px;
    color: #333; font-size: 11px; text-decoration: none;
  }
  .h5-sheet-grid a.on { background: #fff0ee; color: #e10600; }
  .h5-sheet-grid svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
  .h5-sheet-close { width: 100%; min-height: 42px; margin-top: 12px; border: 0; border-radius: 9px; background: #f0efed; color: #555; }

  .h5-top {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; background: #fff; border-bottom: 1px solid #eee;
  }
  .h5-top b { font-size: 14px; }
  .h5-top span { font-size: 11px; color: #999; }
  .h5-back {
    position: fixed; right: 12px; bottom: calc(var(--h5-nav-h) + var(--h5-safe-b) + 14px);
    z-index: 90; width: 38px; height: 38px; border: 0; border-radius: 50%;
    background: rgba(20,14,13,.72); color: #fff; font-size: 17px; display: none;
  }
  .h5-back.on { display: block; }

  /* 自适应学习页 */
  .ev-hero { padding: 14px; border-radius: 12px; color: #fff; background: linear-gradient(135deg,#2b2321,#4d2b25); }
  .ev-hero h3 { margin: 0 0 6px; font-size: 16px; }
  .ev-hero p { margin: 0; font-size: 11px; line-height: 1.6; color: #f0dedb; }
  .ev-rule { display: grid; grid-template-columns: repeat(2,1fr); gap: 8px; margin-top: 10px; }
  .ev-rule div { background: rgba(255,255,255,.1); border-radius: 8px; padding: 8px; }
  .ev-rule span { display: block; font-size: 10px; color: #e6c8c4; }
  .ev-rule b { font-size: 16px; }
  .ev-bars { display: flex; flex-direction: column; gap: 8px; }
  .ev-bar { display: grid; grid-template-columns: 110px 1fr 78px; align-items: center; gap: 8px; font-size: 11px; }
  .ev-bar .track { height: 8px; background: #f0efed; border-radius: 5px; overflow: hidden; }
  .ev-bar .fill { height: 100%; background: #e10600; border-radius: 5px; }
  .ev-bar .fill.low { background: #2fbf6e; }
  .ev-note { font-size: 11px; color: #777; line-height: 1.6; }
  .ev-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
  .ev-actions button { flex: 1 1 auto; }
  .ev-prop { padding: 8px 0; border-bottom: 1px dashed #eee; font-size: 11px; line-height: 1.6; }
  .ev-prop b.ok { color: #1f9d55; }
  .ev-prop b.no { color: #e10600; }
}

@media (min-width: 821px) {
  .h5-nav, .h5-sheet, .h5-back, .h5-top { display: none !important; }
}

@media (max-width: 360px) {
  .h5-nav a { font-size: 9px; }
  .h5-sheet-grid { grid-template-columns: repeat(3, 1fr); }
  .statrow .card b { font-size: 15px !important; }
}
