/* ================================================
   mobile.css - 响应式适配
   断点：1024px（菜单收抽屉）、768px（平板/大手机）、480px（小手机）
   桌面端 >1024px 保留常驻 sidebar，无抽屉
   ================================================ */

/* ==================== ≤ 1024px：菜单收进抽屉 ==================== */
@media (max-width: 1024px) {
  /* 隐藏 topbar 中的菜单链接（移入侧边栏抽屉） */
  .topbar-right > a.topbar-btn[href] {
    display: none !important;
  }

  /* 汉堡菜单按钮显示 */
  .hamburger-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary, var(--text-muted, #64748b));
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
    margin-right: 4px;
    padding: 0;
  }

  .hamburger-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }

  /* 侧边栏 → 抽屉模式 */
  .sidebar {
    position: fixed !important;
    top: var(--topbar-height, 60px);
    left: 0;
    bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* 侧边栏遮罩 */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--topbar-height, 60px);
    left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 998;
  }
  .sidebar-overlay.show {
    display: block;
  }

  /* 主内容区取消侧边栏预留空间 */
  :root { --sidebar-width: 0px; }
  .main-content {
    margin-left: 0 !important;
    max-width: 100% !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
  .app-layout { padding-top: var(--topbar-height); }

  /* 虚拟抽屉（无 sidebar 的页面） */
  .mobile-nav-drawer {
    position: fixed !important;
    top: var(--topbar-height, 60px);
    left: 0;
    bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 999;
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
    background: var(--card-bg, #fff);
    padding: 12px 0;
    overflow-y: auto;
  }
  .mobile-nav-drawer.open {
    transform: translateX(0);
  }
}

/* ==================== > 1024px：隐藏汉堡按钮 ==================== */
@media (min-width: 1025px) {
  .hamburger-btn {
    display: none !important;
  }
  /* 确保桌面端菜单链接正常显示 */
  .topbar-right > a.topbar-btn[href] {
    display: flex !important;
  }
  /* 桌面端 sidebar 恢复正常 — fixed 不占文档流，配合 main-content margin-left */
  .sidebar {
    position: fixed !important;
    transform: none !important;
    box-shadow: none !important;
  }
  .sidebar-overlay {
    display: none !important;
  }
}

/* ==================== ≤ 768px：平板/大手机 ==================== */
@media (max-width: 768px) {

  /* ---------- 全局 ---------- */
  :root {
    --sidebar-width: 0px;
    --topbar-height: 52px;
    --radius: 12px;
    --radius-lg: 16px;
  }

  body {
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
  }

  /* ---------- Topbar ---------- */
  .topbar {
    height: var(--topbar-height);
    padding: 0 12px;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    flex-wrap: nowrap !important;
    overflow: hidden;
  }

  .topbar-left,
  .topbar-right {
    flex-wrap: nowrap !important;
    overflow: hidden;
  }

  .topbar-logo {
    font-size: 15px;
    gap: 6px;
    max-width: 120px;
    overflow: hidden;
    flex-shrink: 0;
  }
  .topbar-logo .logo-icon { font-size: 22px; }
  .topbar-logo span:not(.logo-icon) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* topbar 右侧：只保留汉堡+主题切换+用户头像 */
  .topbar-right {
    gap: 4px;
    justify-content: flex-end;
    flex-shrink: 0;
  }

  .topbar-btn {
    padding: 6px 8px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* 汉堡按钮缩小 */
  .hamburger-btn {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  /* ---------- 主内容 ---------- */
  .main-content {
    margin-left: 0 !important;
    max-width: 100vw !important;
    padding: 12px !important;
    padding-top: calc(var(--topbar-height) + 12px) !important;
  }

  /* index.php 的 .main */
  .main {
    padding: calc(var(--topbar-height) + 12px) 12px 12px;
  }

  /* ---------- 页面标题 ---------- */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 16px;
  }
  .page-title { font-size: 18px; }
  .page-sub { font-size: 12px; }

  /* ---------- 统计卡片 ---------- */
  .board-stats {
    gap: 8px;
  }
  .board-stat {
    padding: 8px 12px;
    flex: 1;
    min-width: 0;
  }
  .board-stat-num { font-size: 18px; }
  .board-stat-label { font-size: 11px; }

  .dashboard-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  /* 仓库统计卡片横向滚动 */
  .wh-stat-cards,
  .wh-stat-cards-wrap {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .wh-stat-card {
    min-width: 70px;
    flex-shrink: 0;
  }

  /* ---------- 看板卡片网格 ---------- */
  .board-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
    gap: 10px !important;
  }
  .board-card {
    padding: 14px !important;
  }
  .board-card-name { font-size: 13px !important; }
  .board-card-spec { font-size: 11px !important; }

  /* ---------- 分类卡片 ---------- */
  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
    gap: 8px !important;
  }
  .category-card {
    padding: 14px 8px !important;
  }
  .category-emoji { font-size: 28px !important; }
  .category-name { font-size: 12px !important; }

  /* ---------- 表格 → 横向滚动 ---------- */
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
  }
  .data-table {
    min-width: 600px;
    font-size: 13px;
  }
  .data-table th {
    font-size: 11px;
    padding: 8px 10px;
    white-space: nowrap;
  }
  .data-table td {
    padding: 8px 10px;
  }

  /* 表格行操作按钮 */
  .data-table .actions,
  .data-table .action-btn,
  .data-table .actions button,
  .data-table .actions a {
    white-space: nowrap;
    padding: 4px 8px;
    font-size: 11px;
  }

  /* ---------- 弹窗 → 全屏 ---------- */
  .modal {
    padding: 0 !important;
  }
  .modal-dialog {
    max-width: 100% !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
  .modal-header {
    padding: 14px 16px;
  }
  .modal-title { font-size: 16px; }
  .modal-body {
    padding: 16px !important;
  }
  .modal-body.detail-body,
  .detail-modal-body {
    padding: 12px 16px !important;
  }
  .modal-actions {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .modal-actions .btn,
  .modal-actions button {
    padding: 6px 12px;
    font-size: 12px;
  }
  .modal-footer {
    padding: 12px 16px;
  }

  /* ---------- 表单 ---------- */
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .form-group label {
    font-size: 13px;
  }
  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 14px; /* ≥16px 避免 iOS 自动缩放 */
    padding: 8px 12px;
  }

  /* ---------- 筛选/工具栏 ---------- */
  .board-tabs {
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .board-tab {
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* 排序按钮组 */
  .sort-btn {
    padding: 4px 8px;
    font-size: 11px;
  }

  /* ---------- 黑板 ---------- */
  .blackboard {
    padding: 14px !important;
    border-radius: 12px;
  }
  .board-header {
    margin-bottom: 14px;
    padding-bottom: 10px;
  }
  .board-title { font-size: 14px; }
  .board-title-stats { font-size: 11px; gap: 8px; }

  /* ---------- 分类组 ---------- */
  .cat-group-header {
    padding: 10px 12px;
  }
  .cat-group-title { font-size: 14px; }
  .cat-group-meta { gap: 8px; font-size: 12px; }
  .cat-group-body { overflow-x: auto; }

  /* ---------- Toast ---------- */
  .toast-container {
    right: 8px !important;
    left: 8px !important;
    top: calc(var(--topbar-height) + 8px) !important;
  }
  .toast {
    max-width: 100% !important;
    font-size: 13px;
    padding: 10px 14px;
  }

  /* ---------- 搜索框 ---------- */
  .search-box,
  .search-input {
    width: 100%;
    max-width: 100%;
  }

  /* ---------- 用户菜单 ---------- */
  .user-btn {
    padding: 6px 8px;
    font-size: 13px;
  }
  .user-btn span:not(.user-avatar) {
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .user-dropdown {
    right: -8px;
    min-width: 160px;
  }

  /* ---------- 借出/维修/坏账页面特化 ---------- */
  .filter-bar,
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .filter-bar select,
  .filter-bar input,
  .toolbar select,
  .toolbar input {
    width: 100%;
  }

  /* ---------- 打印标签页 ---------- */
  .print-toolbar {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }
  .print-toolbar button,
  .print-toolbar .btn {
    width: 100%;
  }

  /* ---------- 回顶按钮 ---------- */
  #backToTop,
  .back-to-top {
    bottom: 80px !important;
    right: 12px !important;
    width: 40px !important;
    height: 40px !important;
    font-size: 18px !important;
  }

  /* ---------- 版本号 ---------- */
  .version-fixed {
    font-size: 10px;
    padding: 4px 8px;
  }

  /* ---------- 复选框列 ---------- */
  .data-table th:first-child,
  .data-table td:first-child {
    min-width: 36px;
  }

  /* ---------- 商品照片 ---------- */
  .data-table img,
  .product-photo img {
    max-width: 50px;
    max-height: 50px;
  }

  /* ---------- 分页 ---------- */
  .pagination {
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
  }
  .pagination a,
  .pagination span {
    padding: 6px 10px;
    font-size: 13px;
  }
}

/* ==================== ≤ 480px：小手机 ==================== */
@media (max-width: 480px) {

  :root {
    --topbar-height: 48px;
  }

  body {
    font-size: 13px;
  }

  /* ---------- Topbar 进一步压缩 ---------- */
  .topbar {
    padding: 0 8px;
  }
  .topbar-logo {
    font-size: 13px;
    max-width: 90px;
  }
  .topbar-logo .logo-icon { font-size: 20px; }

  .topbar-btn {
    padding: 5px 6px;
    font-size: 11px;
  }

  .hamburger-btn {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  /* ---------- 统计卡片单列 ---------- */
  .dashboard-stats {
    grid-template-columns: 1fr 1fr !important;
  }
  .board-stats {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .board-stat {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    padding: 6px 8px;
  }
  .board-stat-num { font-size: 16px; }
  .board-stat-label { font-size: 10px; }

  /* ---------- 看板卡片 → 2 列 ---------- */
  .board-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .board-card {
    padding: 10px !important;
  }
  .board-card-name { font-size: 12px !important; }
  .board-card-spec { font-size: 10px !important; min-height: 0 !important; }
  .board-card-footer { flex-wrap: wrap; }

  /* ---------- 分类卡片 → 3 列 ---------- */
  .category-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 6px !important;
  }
  .category-card {
    padding: 10px 4px !important;
  }
  .category-emoji { font-size: 22px !important; }
  .category-name { font-size: 10px !important; }

  /* ---------- 主内容 padding ---------- */
  .main-content {
    padding: 8px !important;
    padding-top: calc(var(--topbar-height) + 8px) !important;
  }
  .main {
    padding: calc(var(--topbar-height) + 8px) 8px 8px;
  }

  /* ---------- 表格更紧凑 ---------- */
  .data-table {
    min-width: 500px;
    font-size: 12px;
  }
  .data-table th { padding: 6px 8px; font-size: 10px; }
  .data-table td { padding: 6px 8px; }

  /* ---------- 弹窗标题 ---------- */
  .modal-title { font-size: 15px; }
  .modal-header { padding: 12px 14px; }
  .modal-body { padding: 12px !important; }

  /* ---------- 黑板更紧凑 ---------- */
  .blackboard { padding: 10px !important; }
  .board-title { font-size: 13px; }
  .board-title-stats { font-size: 10px; }

  /* ---------- 用户头像/名字 ---------- */
  .user-btn span:not(.user-avatar) { display: none; }
  .user-btn::after { content: '👤'; }

  /* ---------- 商品照片 ---------- */
  .data-table img,
  .product-photo img {
    max-width: 40px;
    max-height: 40px;
  }

  /* ---------- 回顶按钮 ---------- */
  #backToTop,
  .back-to-top {
    bottom: 70px !important;
    right: 8px !important;
    width: 36px !important;
    height: 36px !important;
    font-size: 16px !important;
  }

  /* ---------- 版本号隐藏 ---------- */
  .version-fixed { display: none; }

  /* ---------- Toast ---------- */
  .toast {
    font-size: 12px;
    padding: 8px 12px;
  }
}

/* ==================== 横屏优化 ==================== */
@media (max-width: 900px) and (orientation: landscape) {
  .modal-dialog {
    max-height: 90vh !important;
    margin: 5vh auto !important;
    border-radius: var(--radius) !important;
    height: auto !important;
    width: 90% !important;
    max-width: 600px !important;
  }
}

/* ==================== 安全区域适配（刘海屏） ==================== */
@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    padding-top: env(safe-area-inset-top);
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
  }
  .sidebar,
  .mobile-nav-drawer {
    top: calc(var(--topbar-height) + env(safe-area-inset-top));
  }
  .sidebar-overlay {
    top: calc(var(--topbar-height) + env(safe-area-inset-top));
  }
}
