/* ============ 移动端适配 ============
   断点：900 侧栏抽屉 / 760 表格卡片化 / 640 弹窗与表单 / 480 细节
   本文件最后加载，用于覆盖桌面端样式。 */

/* ---------- 通用触摸体验 ---------- */
button, .btn, .nav-item, .seg button, .tabs button, .quick-btn, .demo-row {
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 平板 / 手机：侧边栏抽屉 ---------- */
@media (max-width: 900px) {
  .sidebar {
    width: min(280px, 84vw);
    padding: 18px 12px calc(14px + env(safe-area-inset-bottom));
  }
  .nav-item { min-height: 44px; padding: 11px 12px; font-size: 14px; }
  .nav-item svg { width: 18px; height: 18px; flex-basis: 18px; }
  .brand { padding-bottom: 16px; }
  .side-foot { padding-bottom: 4px; }
  .menu-toggle { width: 38px; height: 38px; flex: 0 0 38px; }
}

/* ---------- 手机：顶栏 / 内容区 ---------- */
@media (max-width: 640px) {
  .topbar { padding: 9px 12px; gap: 8px; }
  .topbar h1 { font-size: 15.5px; }
  .topbar .row { flex: 1; min-width: 0; gap: 8px; }
  #page-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-actions { gap: 6px; flex: 0 0 auto; }
  .top-actions .chip.num { display: none; }
  .top-actions .chip { padding: 2px 7px; font-size: 10.5px; }
  .view { padding: 14px 12px 72px; }
}

@media (max-width: 560px) {
  .view { padding: 12px 12px 72px; }
  .card { border-radius: 12px; }
  .card-h { padding: 13px 14px 0; }
  .card-h h3 { font-size: 13.5px; }
  .card-b { padding: 12px 14px 16px; }
  .card-b.tight { padding: 6px 14px 10px; }
}

/* ---------- KPI：手机上固定两列 ---------- */
@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px 12px 11px; border-radius: 12px; }
  .kpi .k-label { font-size: 10.5px; }
  .kpi .k-val { font-size: 22px; margin: 4px 0 1px; letter-spacing: -.4px; }
  .kpi .k-foot { font-size: 10.5px; line-height: 1.4; }
}

/* ---------- 工具条：搜索占满、筛选两列、主动作整行 ---------- */
@media (max-width: 640px) {
  .toolbar { gap: 8px; margin-bottom: 10px; }
  .toolbar .search { flex: 1 1 100%; max-width: none; min-width: 0; }
  .toolbar .select { flex: 1 1 calc(50% - 4px); width: auto !important; min-width: 0; }
  .toolbar .spacer { display: none; }
  .toolbar > .btn-primary { flex: 1 1 100%; min-height: 40px; }
  .toolbar > .sub { flex: 1 1 100%; }
  .seg {
    width: 100%; flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: 1 0 auto; white-space: nowrap; padding: 7px 11px; }
}

/* ---------- 表格：760 以下改为卡片式列表 ---------- */
@media (max-width: 760px) {
  .tbl-wrap {
    background: transparent; border: 0; box-shadow: none; overflow: visible;
  }
  .tbl-wrap table, .tbl-wrap tbody { display: block; width: 100%; }
  .tbl-wrap thead { display: none; }

  .tbl-wrap tbody tr {
    display: block;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  .tbl-wrap tbody tr:hover { background: var(--panel); }
  .tbl-wrap tbody tr:last-child { margin-bottom: 0; }

  .tbl-wrap tbody td {
    display: block; position: relative;
    padding: 4px 0 4px 90px;
    border: 0; font-size: 13px; line-height: 1.65;
  }
  .tbl-wrap tbody td::before {
    content: attr(data-label);
    position: absolute; left: 0; top: 5px; width: 82px;
    font-size: 11.5px; color: var(--muted); line-height: 1.7;
  }

  /* 主信息行 */
  .tbl-wrap tbody td.td-main {
    padding: 0 0 9px; margin-bottom: 7px;
    border-bottom: 1px dashed #eceee9;
    max-width: none !important;
  }
  .tbl-wrap tbody td.td-main::before { display: none; }
  .tbl-wrap tbody td.td-main .cust-cell { min-width: 0; }
  .tbl-wrap tbody td.td-main .cell-main { font-size: 14px; }
  .tbl-wrap tbody td.td-main .ellipsis { white-space: normal; }

  /* 长文本内容：标签在上，全文展开 */
  .tbl-wrap tbody td.td-block { padding-left: 0; }
  .tbl-wrap tbody td.td-block::before {
    position: static; display: block; width: auto; margin-bottom: 2px;
  }
  .tbl-wrap tbody td.td-block .ellipsis { white-space: normal; overflow: visible; }

  /* 行内操作 */
  .tbl-wrap tbody td.td-actions {
    padding: 9px 0 0; margin-top: 7px;
    border-top: 1px dashed #eceee9;
  }
  .tbl-wrap tbody td.td-actions::before { display: none; }
  .tbl-wrap tbody td.td-actions > .btn { width: 100%; min-height: 38px; }
  .tbl-wrap tbody td.td-actions .row-actions { display: flex; gap: 8px; }
  .tbl-wrap tbody td.td-actions .row-actions .btn { flex: 1; width: auto; min-height: 38px; }

  .tbl-wrap .table-foot {
    border: 0; background: transparent; padding: 6px 2px 0;
    font-size: 11.5px;
  }
  .health { max-width: 200px; }
}

/* ---------- 弹窗：手机端底部抽屉式 ---------- */
@media (max-width: 640px) {
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal {
    max-width: none; width: 100%; max-height: 92vh;
    border-radius: 16px 16px 0 0;
    animation: sheetIn .22s ease both;
  }
  @keyframes sheetIn { from { transform: translateY(28px); opacity: .7; } to { transform: none; opacity: 1; } }
  .modal-h { padding: 16px 16px 8px; }
  .modal-h h3 { font-size: 15.5px; }
  .modal-b { padding: 4px 16px 6px; }
  .modal-f {
    padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  .modal-f .btn { flex: 1; min-height: 42px; }

  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .form-grid .span2 { grid-column: auto; }
  .field { margin-bottom: 12px; }
  .input, .select, textarea, .chip-input input { font-size: 16px; }
  textarea { min-height: 84px; }
}

/* ---------- 详情抽屉：手机全屏 ---------- */
@media (max-width: 640px) {
  .drawer { width: 100%; }
  .drawer-h { padding: 16px 16px 12px; }
  .drawer-h h2 { font-size: 16.5px; }
  .drawer-b { padding: 14px 16px 32px; }
  .drawer-f {
    flex-wrap: wrap; gap: 8px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  }
  .drawer-f > div:last-child { flex: 1 1 100%; display: flex; gap: 8px; }
  .drawer-f > div:last-child .btn { flex: 1; min-height: 40px; }
  .drawer-f .btn-sm { min-height: 40px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 1 0 auto; white-space: nowrap; padding: 9px 11px; }
}

@media (max-width: 560px) {
  .detail-grid { grid-template-columns: 1fr; gap: 9px; }
  .detail-item .v { word-break: break-word; }
  .info-box { padding: 11px 12px; }
}

/* ---------- 工作台 ---------- */
@media (max-width: 640px) {
  .dash-grid { margin-top: 10px; gap: 10px; }
  .quick-btn { min-height: 46px; }
  .alert-row { flex-wrap: wrap; row-gap: 6px; }
  .alert-row .grow { flex: 1 1 calc(100% - 34px); }
  .alert-row .tag { margin-left: 32px; }
  .alert-row .btn { margin-left: auto; }
  .list-row { gap: 10px; }
  .list-row .name { font-size: 12.5px; }
}

/* ---------- 信息采集 ---------- */
@media (max-width: 1080px) {
  .collect-grid { grid-template-columns: 1fr !important; }
}
@media (max-width: 640px) {
  .platform-grid { grid-template-columns: 1fr 1fr; }
  .platform-item { padding: 8px 10px; font-size: 12px; }
  .collect-note { font-size: 11.5px; }
  .log-row { font-size: 12px; }
}

@media (max-width: 400px) {
  .platform-grid { grid-template-columns: 1fr; }
}

/* ---------- 登录页 ---------- */
@media (max-width: 640px) {
  .login-wrap, .login-panel { min-height: 100dvh; }
  .login-panel { padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
  .login-card { padding: 26px 20px 20px; border-radius: 14px; }
  .login-card h2 { font-size: 19px; }
  .demo-row { flex-wrap: wrap; row-gap: 2px; }
  .demo-row em { margin-left: 38px; width: 100%; }
}

/* ---------- 其他细节 ---------- */
@media (max-width: 560px) {
  .toast-root { top: 10px; width: calc(100% - 24px); }
  .toast { max-width: 100%; font-size: 12.5px; text-align: center; }
  .empty { padding: 34px 16px; }
  .status-line { gap: 5px; }
  .section-title { margin: 16px 0 7px; }
  .table-foot { flex-wrap: wrap; gap: 4px; }
}
