
/* ===== Batch 11: Mobile Responsive Design v94 ===== */

/* Mobile hamburger menu */
.mobile-header {
  display: none;
}

@media (max-width: 768px) {
  /* Mobile header with hamburger */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    height: calc(48px + env(safe-area-inset-top));
    min-height: 48px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  }

  .mobile-header .hamburger {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    background: transparent;
    font-size: 22px;
    color: var(--text);
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, transform 0.1s;
  }

  .mobile-header .hamburger:active {
    background: var(--bg-hover);
    transform: scale(0.92);
  }

  .mobile-header .mobile-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
  }

  /* Override desktop layout for mobile */
  .layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    min-width: 0 !important;
  }

  /* Sidebar becomes off-canvas drawer */
  .sidebar {
    position: fixed;
    left: -300px;
    top: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    z-index: 300;
    transition: left 0.3s cubic-bezier(.32,.72,.38,1), box-shadow 0.3s;
    box-shadow: 2px 0 12px rgba(0,0,0,0.12);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.sidebar-open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
  }

  /* Backdrop for sidebar drawer */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.35);
    z-index: 250;
    opacity: 0;
    transition: opacity 0.3s;
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-backdrop.active {
    display: block;
    opacity: 1;
  }

  /* Sidebar 导航项当前页高亮 */
  .sidebar-nav .nav-item {
    position: relative;
    border-radius: 10px;
    margin: 0 6px;
    transition: background 0.15s;
  }
  .sidebar-nav .nav-item[aria-current="page"],
  .sidebar-nav .nav-item.nav-item--active {
    background: var(--primary-light, rgba(99,102,241,0.1));
    color: var(--primary);
    font-weight: 600;
  }
  .sidebar-nav .nav-item[aria-current="page"]::before,
  .sidebar-nav .nav-item.nav-item--active::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 10px;
    bottom: 10px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--primary);
  }

  /* 子菜单展开动画 */
  .nav-submenu {
    overflow: hidden;
    transition: max-height 0.25s ease-out, opacity 0.2s;
    max-height: 0;
    opacity: 0;
  }
  .nav-submenu[style*="display: block"],
  .nav-submenu[style*="block"] {
    max-height: 300px;
    opacity: 1;
  }

  /* Main area takes full width */
  .main {
    flex: 1;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  /* Topbar hidden on mobile, replaced by mobile-header */
  .topbar {
    display: none;
  }

  .content {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  /* Stats grid: 2 columns on tablet, 1 on phone */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  @media (max-width: 480px) {
    .stats-grid {
      grid-template-columns: 1fr !important;
    }
  }

  /* Tables: horizontal scroll with card fallback */
  .table-container, .table-responsive {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 240px);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .data-table {
    min-width: 600px;
    font-size: 12px;
  }

  /* ===== v95 功能页表格手机端体验 ===== */
  /* 行高与触摸目标：覆盖 style.css .data-table td 6px/10px，同选择器特异性更高 */
  .table-responsive .data-table td,
  .table-container .data-table td {
    padding: 11px 12px;
  }
  .table-responsive .data-table th,
  .table-container .data-table th {
    padding: 12px 14px;
    font-size: 12px;
  }
  /* 行交替色：tr 背景 (0,2,2) 与 style.css hover 同特异、由后加载的 style.css 覆盖；
     sticky 列底色同步；合计行用 !important 保持高亮 */
  .data-table tbody tr:nth-child(even) {
    background: var(--surface-3);
  }
  .data-table tbody tr:nth-child(even) td.sticky-left,
  .data-table tbody tr:nth-child(even) td.sticky-right {
    background: var(--surface-3);
  }
  .data-table tbody tr.summary-row {
    background: var(--bg-hover) !important;
  }
  .data-table tbody tr.summary-row td {
    background: var(--bg-hover) !important;
  }
  /* 模态框内明细表容器：不受页面级 max-height 限制，避免双层滚动条 */
  .modal .table-responsive,
  .modal .table-container {
    max-height: none;
  }
  /* 明细表内删除按钮在手机上保持可触尺寸 */
  .item-table-wrap .btn {
    min-height: 38px;
    padding: 0 10px;
  }
  /* 操作列：按钮加高、间距加大（覆盖 enhancements.css 28px/4px 与 batch5 6px） */
  .table-responsive .row-actions,
  .table-container .row-actions {
    gap: 8px;
  }
  .table-responsive .row-actions button,
  .table-container .row-actions button {
    min-height: 38px;
    height: auto;
    padding: 0 12px;
    font-size: 13px;
  }
  /* 筛选条输入加高 34px -> 44px */
  .filter-item .input,
  .filter-item .select {
    height: 44px !important;
  }

  /* Card list: single column */
  .card-list {
    grid-template-columns: 1fr !important;
  }

  /* Forms: stack vertically */
  .form-row {
    flex-direction: column !important;
    gap: 0 !important;
  }

  .form-row .form-group {
    width: 100% !important;
  }

  /* Input font 16px to prevent iOS zoom */
  .input, .select, .textarea {
    font-size: 16px !important;
  }

  /* ===== v95 功能页表单手机端体验 ===== */
  /* 输入框加大：覆盖 style.css .input min-height:36px / padding:8px 12px；
     textarea 单独保持大高度（style.css .textarea min-height:80px） */
  .input, .select {
    min-height: 46px !important;
    padding: 11px 14px !important;
    border-radius: 10px !important;
  }
  .textarea {
    min-height: 100px !important;
    padding: 11px 14px !important;
    border-radius: 10px !important;
  }
  /* 标签增大并拉开与输入框的距离 */
  .form-group .label {
    font-size: 14px !important;
    margin-bottom: 8px !important;
  }
  /* 表单分组间距更明确 */
  .form-stack .form-group {
    margin-bottom: 20px !important;
  }
  /* 焦点环强调（覆盖 style.css 已有基础环，确保手机端清晰可见） */
  .input:focus, .select:focus, .textarea:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px var(--primary-bg) !important;
  }
  /* 内联 grid 双列表单（clients.js 等）压成单列：内联 display:grid 被外部 !important 覆盖 */
  .form-row[style*="grid-template-columns"] {
    display: block !important;
  }
  /* 报销明细录入表内输入：表格内紧凑但相较桌面放大 */
  .table-responsive .item-table .select,
  .table-responsive .item-table .input {
    min-height: 38px !important;
    font-size: 14px !important;
    padding: 7px 10px !important;
  }
  .item-table .select,
  .item-table .input {
    min-height: 38px !important;
    font-size: 14px !important;
    padding: 7px 10px !important;
  }

  /* Buttons: min 44px height for touch */
  .btn {
    min-height: 44px;
  }

  .btn-xs, .btn-sm {
    min-height: 44px;
  }

  /* Modal: nearly full screen but with breathing room on phones */
  .modal {
    max-width: 96vw !important;
    max-height: 92vh !important;
    width: 100% !important;
    height: auto !important;
    border-radius: 14px !important;
    margin: auto !important;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2) !important;
  }

  .modal-body {
    padding: 12px;
    max-height: calc(92vh - 120px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Data table readability on very small screens */
  .data-table {
    min-width: 480px;
    font-size: 12px;
  }

  /* Prevent horizontal overflow in content area */
  .content {
    min-width: 0;
    overflow-x: hidden;
  }

  /* Kanban: horizontal scroll */
  .kanban-board {
    overflow-x: auto;
    gap: 10px;
    padding-bottom: 8px;
  }

  .kanban-column {
    min-width: 260px;
    max-width: 280px;
  }

  /* Gantt chart: horizontal scroll */
  .gantt-chart {
    overflow-x: auto;
  }

  /* Toast: full width on mobile */
  .toast {
    top: 8px;
    left: 8px;
    right: 8px;
    max-width: none;
    text-align: center;
    font-size: 13px;
    border-radius: 10px;
  }

  /* Summary cards: stack */
  .summary-cards {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  @media (max-width: 480px) {
    .summary-cards {
      grid-template-columns: 1fr !important;
    }
  }

  /* User card: simplified */
  .user-card {
    padding: 8px;
    min-height: 44px;
  }

  .sidebar-header {
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .sidebar-title {
    font-size: 14px;
    font-weight: 700;
  }

  .sidebar-search {
    padding: 6px 8px;
  }

  /* Pagination controls: simplified */
  .pagination {
    flex-wrap: wrap;
    gap: 4px;
  }

  /* 用户菜单（含退出登录）：手机端悬浮于 header 下方右侧 */
  #userDropdownMenu {
    position: fixed !important;
    top: 56px !important;
    top: calc(48px + env(safe-area-inset-top, 0px)) !important;
    right: 12px !important;
    left: auto !important;
    width: 220px !important;
    max-width: calc(100vw - 24px) !important;
    z-index: 400 !important;
    max-height: calc(100vh - 70px);
    overflow-y: auto;
    border-radius: 12px !important;
    box-shadow: 0 12px 40px rgba(0,0,0,0.15) !important;
    animation: dropdownSlideIn 0.15s ease-out;
  }
  @keyframes dropdownSlideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* Touch-friendly tap targets */
@media (hover: none) and (pointer: coarse) {
  .nav-item {
    min-height: 44px;
    padding: 10px 12px;
  }

  .dropdown-item {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 15px;
  }

  .btn:active {
    transform: scale(0.97);
  }
}

/* 暗色模式增强 */
@media (max-width: 768px) {
  [data-theme="dark"] .mobile-header {
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }
  [data-theme="dark"] .sidebar {
    box-shadow: 2px 0 16px rgba(0,0,0,0.3);
  }
  [data-theme="dark"] .sidebar.sidebar-open {
    box-shadow: 4px 0 28px rgba(0,0,0,0.4);
  }
  [data-theme="dark"] .sidebar-backdrop.active {
    background: rgba(0,0,0,0.55);
  }
}