/* ============================================================
   上号器管理系统 · 移动端适配层  mobile.css
   v2.7.63  功能9：在手机 / 平板上一键适配全部页面
   作用：只做"窄屏兜底"，不覆盖任何桌面端已有样式
   ============================================================ */

/* ---------- 0. 基础：防止横向溢出、输入框缩放 ---------- */
html, body {
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  /* 移动端点击不要有蓝色高亮 */
  -webkit-tap-highlight-color: transparent;
}

/* iOS 上 input 字号 < 16px 会触发自动放大页面 —— 手机端统一拉到 16px */
@media (max-width: 767px) {
  input, select, textarea, button {
    font-size: 16px !important;
  }
}

/* ---------- 1. 通用容器收边 ---------- */
@media (max-width: 767px) {
  .container,
  .wrap,
  .main,
  .content,
  .page,
  .page-wrap,
  .container-fluid {
    max-width: 100% !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
    box-sizing: border-box;
  }
}

/* ---------- 2. 顶部导航 ---------- */
@media (max-width: 767px) {
  .top-nav {
    padding: 8px 10px !important;
    gap: 8px !important;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .top-nav::-webkit-scrollbar { display: none; }

  .top-nav .nav-title {
    font-size: 15px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1 1 auto;
    min-width: 0;
  }
  .top-nav .nav-link,
  .top-nav .back-btn {
    flex: 0 0 auto;
    padding: 6px 10px !important;
    font-size: 13px !important;
    white-space: nowrap;
  }
}

/* ---------- 3. 功能卡片网格：手机上自动变 2 列 → 1 列 ---------- */
@media (max-width: 767px) {
  .card-group,
  .func-grid,
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  .func-card {
    padding: 12px !important;
    min-height: 0 !important;
  }
  .func-card .fc-title { font-size: 14px !important; }
  .func-card .fc-desc {
    font-size: 11.5px !important;
    line-height: 1.35 !important;
    /* 描述最多两行，防止卡片高矮不齐 */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .func-card .fc-icon svg { width: 18px; height: 18px; }
}
@media (max-width: 400px) {
  .card-group,
  .func-grid,
  .grid { grid-template-columns: 1fr !important; }
}

/* ---------- 4. 表格：手机上横向滚动，不要压缩文字 ---------- */
@media (max-width: 767px) {
  .table-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px !important;
  }
  .table-wrapper table {
    min-width: 640px;   /* 保证列不被挤扁，靠横向滑动查看 */
  }
  table th, table td {
    padding: 9px 10px !important;
    font-size: 13px !important;
    white-space: nowrap;
  }
  /* 表格里过长的文本截断 */
  table td .ellipsis,
  table td.ellipsis {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* ---------- 5. 筛选 / 搜索区：手机上竖排，输入框占满 ---------- */
@media (max-width: 767px) {
  .filters,
  .filter-bar,
  .search-bar,
  .toolbar,
  .filter-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .filters > *,
  .filter-bar > *,
  .search-bar > *,
  .toolbar > *,
  .filter-row > * {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
  }
  /* 固定像素宽度的输入框在手机上撑满 */
  input[style*="width:190px"],
  input[style*="width:140px"],
  select[style*="width:190px"],
  select[style*="width:140px"] {
    width: 100% !important;
  }
}

/* ---------- 6. 按钮组：等分排列，手指好点 ---------- */
@media (max-width: 767px) {
  .btn-group,
  .actions,
  .btn-row,
  .op-btns {
    display: flex !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
  }
  .btn-group > *,
  .actions > *,
  .btn-row > * {
    flex: 1 1 auto;
    min-width: 0;
  }
  .btn, button.btn, a.btn {
    min-height: 40px;      /* 触摸目标 ≥40px */
    padding: 9px 14px !important;
    font-size: 14px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* ---------- 7. 统计卡片：3 列 → 自动换行 ---------- */
@media (max-width: 767px) {
  .statWrap,
  .stats,
  .stat-row,
  .kpi-row {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)) !important;
    gap: 8px !important;
  }
  .statCell,
  .stat-card,
  .kpi-card {
    padding: 10px !important;
    min-width: 0 !important;
  }
  .statCell .num,
  .stat-card .num,
  .kpi-card .val {
    font-size: 20px !important;
  }
  .statCell .lbl,
  .stat-card .lbl,
  .kpi-card .lbl {
    font-size: 11px !important;
  }
}

/* ---------- 8. 列表条目：左色条 + 内边距收窄 ---------- */
@media (max-width: 767px) {
  .log-item,
  .item,
  .row-item,
  .list-item {
    padding: 11px 11px !important;
    border-radius: 12px !important;
  }
  .log-item .meta,
  .item .meta,
  .row-item .meta {
    font-size: 11.5px !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
}

/* ---------- 9. 弹窗 / 抽屉：全屏化 ---------- */
@media (max-width: 767px) {
  .modal,
  .dialog,
  .popup,
  .drawer {
    width: auto !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100vh - 80px) !important;
    margin: 0 auto !important;
    border-radius: 16px !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-mask,
  .mask {
    padding: 12px;
    box-sizing: border-box;
  }
}

/* ---------- 10. 图表 / 可视化：限制高度 ---------- */
@media (max-width: 767px) {
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }
  .chart-box,
  .trend,
  .chart {
    max-height: 220px !important;
    overflow-x: auto;
  }
}

/* ---------- 11. 长代码 / 长 URL 不撑破布局 ---------- */
@media (max-width: 767px) {
  pre, code, .code, .mono, .url, .link-text {
    white-space: pre-wrap !important;
    word-break: break-all !important;
    overflow-wrap: anywhere !important;
    max-width: 100%;
  }
}

/* ---------- 12. 底部安全区（全面屏手势条） ---------- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-footer,
  .footer-bar,
  .bottom-bar {
    padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
  }
}

/* ---------- 13. Tab 切换条：手机上可横向滑动 ---------- */
@media (max-width: 767px) {
  .tabs,
  .tab-bar,
  .tab-group {
    display: flex !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px !important;
  }
  .tabs::-webkit-scrollbar,
  .tab-bar::-webkit-scrollbar { display: none; }
  .tabs > *,
  .tab-bar > *,
  .tab-group > * {
    flex: 0 0 auto !important;
    white-space: nowrap;
    padding: 8px 14px !important;
    font-size: 13px !important;
  }
}

/* ---------- 14. 超窄屏（≤360px）额外收边 ---------- */
@media (max-width: 360px) {
  .container, .wrap, .main, .content, .page {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  .func-card { padding: 10px !important; }
  .func-card .fc-desc { font-size: 11px !important; }
  table th, table td { padding: 8px !important; font-size: 12px !important; }
}

/* ---------- 15. 横屏手机 ---------- */
@media (max-width: 767px) and (orientation: landscape) {
  .func-card { padding: 10px !important; }
  .statWrap, .stats, .kpi-row { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)) !important; }
}

/* ---------- 16. 触屏设备：hover 效果关掉，避免"粘住" ---------- */
@media (hover: none) {
  .func-card:hover,
  .btn:hover {
    transform: none !important;
  }
}
