/* ── 移动端响应式适配 — 仅在小屏幕生效，不影响桌面布局 ──────────────────
   断点：≤ 768px 视为移动端
   ─────────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {

  /* ── 布局 ────────────────────────────────────────────────────────────── */
  #app {
    flex-direction: column;
  }

  /* 侧边栏：默认隐藏，通过 .sidebar-open 显示 */
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 260px;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1000;
    overflow-y: auto;
  }

  #sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }

  /* 遮罩层 */
  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
  }
  #sidebar-overlay.active { display: block; }

  /* 主区域占满全宽 */
  #main {
    margin-left: 0 !important;
    width: 100%;
    min-width: 0;
  }

  /* ── 顶栏 ────────────────────────────────────────────────────────────── */
  #topbar {
    padding: 0 12px;
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .topbar-toggle {
    display: flex !important;
    font-size: 22px;
    width: 36px;
    height: 36px;
  }

  .topbar-title {
    font-size: 15px;
    flex: 1;
    text-align: center;
  }

  .user-info { display: none; }

  /* ── 内容区 ──────────────────────────────────────────────────────────── */
  #content {
    padding: 10px;
    overflow-x: hidden;
  }

  /* ── 通用表格：横向滚动 ──────────────────────────────────────────────── */
  .table-wrap,
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 600px;
  }

  /* ── 搜索栏：紧凑单行横向滚动（不再堆叠占满屏幕）──────────────────── */
  .search-bar {
    flex-wrap: nowrap !important;
    gap: 6px !important;
    padding: 8px 10px !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    align-items: center;
  }

  .search-bar input,
  .search-bar select {
    width: auto !important;
    min-width: 100px;
    max-width: 140px;
    flex: 0 0 auto !important;
    height: 32px !important;
    font-size: 12px;
    box-sizing: border-box;
  }

  .search-bar input[type="date"] {
    min-width: 108px;
  }

  .search-bar .btn {
    width: auto !important;
    flex: 0 0 auto !important;
    height: 32px !important;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* ── 折叠的搜索栏（移动端默认收起，点击按钮展开）──────────────────── */
  .mb-collapsed {
    display: none !important;
  }

  .mb-collapse-btn {
    display: flex !important;
    align-items: center;
    gap: 6px;
    width: 100%;
    height: 34px;
    padding: 0 12px;
    margin-bottom: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
  }
  .mb-collapse-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
  }

  /* ── 页面标题行：压缩 ───────────────────────────────────────────────── */
  .page-header {
    padding: 8px 0 !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
  }

  .page-header .page-title {
    font-size: 15px !important;
    white-space: nowrap;
  }

  .page-actions {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px !important;
  }

  .page-actions .btn {
    flex: 0 0 auto !important;
    min-width: 0 !important;
    font-size: 12px;
    padding: 8px 10px;
    white-space: nowrap;
  }

  /* ── 图表卡片 ────────────────────────────────────────────────────────── */
  .chart-card {
    padding: 12px !important;
  }

  /* 仪表盘图表高度适配 */
  #dashboardChart {
    max-height: 220px !important;
  }

  /* ── 分红核算：禁用 sticky 表头（手机上性能差） ───────────────────── */
  @supports not (position: sticky) {
    .sd-title { position: static; }
  }

  /* ── 分页控件 ────────────────────────────────────────────────────────── */
  .pagination {
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 4px !important;
  }

  /* ── 登录页 ──────────────────────────────────────────────────────────── */
  .login-card {
    width: 92vw !important;
    padding: 24px 20px !important;
  }

  /* ── 快速操作按钮放大（手机触控友好）──────────────────────────────── */
  .btn-sm {
    min-height: 32px;
    padding: 6px 10px;
  }

  /* ── 通知图标 ────────────────────────────────────────────────────────── */
  #notif-icon-wrap {
    margin-right: 6px !important;
  }

  /* ── 固定底部安全区（iPhone 刘海屏）───────────────────────────────── */
  #content {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  #topbar {
    padding-top: env(safe-area-inset-top);
  }
}

/* ── 超小屏（≤ 480px）────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr !important;
  }

  #content {
    padding: 8px;
  }

  table {
    font-size: 11px !important;
  }

  .btn {
    font-size: 12px;
  }
}

/* ── PWA 独立模式：隐藏不必要的元素 ────────────────────────────────── */
@media (display-mode: standalone) {
  /* standalone 模式下顶部多留安全区 */
  #topbar {
    padding-top: env(safe-area-inset-top);
    height: calc(52px + env(safe-area-inset-top));
  }
}
