/* 移动优先补充:<1024px 侧栏变抽屉,<640px 表格变分组行 */

@media (max-width: 1023px) {
  .sidenav {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 45;
    height: 100vh; height: 100dvh;
    width: min(320px, 88vw);
    transform: translateX(-105%);
    transition: transform var(--speed) ease;
    box-shadow: var(--shadow-float);
    background: var(--surface);
    padding-top: 8px;
    padding-bottom: calc(48px + env(safe-area-inset-bottom));
  }
  .sidenav.open { transform: translateX(0); }
  .sidenav .drawer-close { display: flex; margin: 4px 8px 8px auto; }
}

@media (min-width: 1024px) {
  .menu-btn, .sidenav .drawer-close { display: none; }
}

@media (max-width: 767px) {
  :root { --fs-body: 16px; --fs-h1: 24px; --fs-h2: 20px; --fs-h3: 17px; }
  .main { padding: 24px 16px 96px; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .tool .tool-grid { grid-template-columns: 1fr; }
  .fs-impact { grid-template-columns: 1fr; }
  .pager { flex-direction: column; }
  .pager a { max-width: none; }
  .home-actions .btn { flex: 1; }

  /* 侧面板变为底部面板 */
  .sidepanel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%; max-height: 82vh; max-height: 82dvh;
    border-left: none; border-top: 1px solid var(--line);
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    transform: translateY(105%);
  }
  .sidepanel.open { transform: translateY(0); }
  .sidepanel .panel-body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { border-radius: var(--radius-panel) var(--radius-panel) 0 0; max-width: none; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}

/* 窄屏表格 → 分组行。需要 table.rwd 且 td 带 data-label */
@media (max-width: 639px) {
  /* 搜索浮层在小屏为全屏 */
  .search-overlay { padding: 0; align-items: stretch; }
  .search-panel {
    max-width: none; max-height: none; height: 100vh; height: 100dvh;
    border: none; border-radius: 0; box-shadow: none;
  }
  .search-panel .sp-head { padding-top: calc(10px + env(safe-area-inset-top)); }
  .search-panel .sp-body { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

  table.rwd thead { position: absolute; clip: rect(0 0 0 0); width: 1px; height: 1px; overflow: hidden; }
  table.rwd tr { display: block; border: 1px solid var(--line); border-radius: var(--radius-ctl); margin-bottom: 12px; padding: 4px 0; }
  table.rwd td {
    display: flex; justify-content: space-between; gap: 16px;
    border: none; padding: 6px 12px; text-align: right;
  }
  table.rwd td::before {
    content: attr(data-label);
    font-weight: 600; color: var(--ink-2); text-align: left; flex-shrink: 0;
  }
  /* 宽数据表:提供可滚动容器(表格自然收缩,超宽时才出现横向滚动) */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 16px 0 24px; }
  .table-scroll table { margin: 0; }
  .orderbook { font-size: 13px; }
}

@media (min-width: 640px) {
  .table-scroll { margin: 0; }
}

/* 打印:隐藏导航 */
@media print {
  .topbar, .sidenav, .pager, .scrim, .sidepanel { display: none !important; }
  .main { padding: 0; }
}
