/* ============================================================
   와이비 OMS — Mobile Responsive Styles v9.0
   - 768px 이하: 사이드바→바텀네비, 모바일 최적화
   - 1024px 이하: 태블릿 대응
   ============================================================ */

/* ─── CSS Variables ─── */
:root {
  --bottom-nav-h: 64px;
  --mobile-header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─── 모바일 (768px 이하) ─── */
@media (max-width: 768px) {
  /* 사이드바 숨김 */
  .desktop-sidebar { display: none !important; }

  /* 메인 레이아웃 전환 */
  .layout-root {
    flex-direction: column !important;
    height: 100vh;
    height: 100dvh;
  }

  /* 모바일 헤더 */
  .mobile-header {
    display: flex !important;
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--mobile-header-h);
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 12px;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
  }
  .mobile-header .logo { 
    width: 32px; height: 32px; 
    background: #2563eb; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .mobile-header .logo i { color: white; font-size: 14px; }
  .mobile-header .title { font-weight: 700; font-size: 15px; color: #1f2937; flex: 1; }
  .mobile-header .header-actions { display: flex; gap: 4px; align-items: center; }
  .mobile-header .header-btn {
    width: 36px; height: 36px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #6b7280; background: transparent;
    border: none; cursor: pointer; position: relative;
  }
  .mobile-header .header-btn:active { background: #f3f4f6; }

  /* 메인 컨텐츠 영역 */
  .main-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px);
  }
  .main-content #content {
    padding: 12px !important;
  }

  /* 바텀 네비게이션 */
  .bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: white;
    border-top: 1px solid #e5e7eb;
    z-index: 50;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
  }
  .bottom-nav-inner {
    display: flex;
    width: 100%;
    height: var(--bottom-nav-h);
    align-items: stretch;
  }
  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: #9ca3af;
    text-decoration: none;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 4px 0;
    position: relative;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav-item i { font-size: 18px; }
  .bottom-nav-item span { font-size: 10px; font-weight: 500; line-height: 1.2; }
  .bottom-nav-item.active { color: #2563eb; }
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0; left: 25%; right: 25%;
    height: 2px;
    background: #2563eb;
    border-radius: 0 0 2px 2px;
  }
  .bottom-nav-item .nav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 16px);
    min-width: 16px; height: 16px;
    background: #ef4444;
    color: white;
    font-size: 9px;
    font-weight: 700;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
  }

  /* 더보기 메뉴 (풀스크린 오버레이) */
  .mobile-more-menu {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: flex-end;
    animation: fadeIn 0.15s;
  }
  .mobile-more-panel {
    width: 100%;
    max-height: 70vh;
    background: white;
    border-radius: 16px 16px 0 0;
    padding: 8px 0 calc(var(--safe-bottom) + 16px);
    overflow-y: auto;
    animation: slideUp 0.2s ease-out;
  }
  .mobile-more-panel .drag-handle {
    width: 36px; height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 4px auto 12px;
  }
  .mobile-more-panel .menu-group-label {
    padding: 8px 20px 4px;
    font-size: 10px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  .mobile-more-panel .more-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    width: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #374151;
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-more-panel .more-menu-item:active { background: #f3f4f6; }
  .mobile-more-panel .more-menu-item i { width: 20px; text-align: center; color: #6b7280; }
  .mobile-more-panel .more-menu-item.active { color: #2563eb; font-weight: 600; }
  .mobile-more-panel .more-menu-item.active i { color: #2563eb; }

  /* 사용자 프로필 (더보기 하단) */
  .mobile-more-panel .user-section {
    border-top: 1px solid #e5e7eb;
    margin-top: 8px;
    padding: 12px 20px 0;
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .mobile-more-panel .user-section .avatar {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .mobile-more-panel .user-section .avatar i { color: white; font-size: 14px; }
  .mobile-more-panel .user-actions {
    display: flex; gap: 8px; padding: 8px 20px;
  }
  .mobile-more-panel .user-actions button {
    flex: 1; padding: 8px; border-radius: 8px;
    font-size: 12px; border: 1px solid #e5e7eb;
    background: white; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 4px;
  }
  .mobile-more-panel .user-actions button:active { background: #f3f4f6; }
  .mobile-more-panel .user-actions .logout-btn { color: #dc2626; border-color: #fecaca; }

  /* ─── 컨텐츠 반응형 ─── */
  
  /* 대시보드 카드 그리드 */
  .grid.grid-cols-4,
  .grid.grid-cols-3 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  
  /* 테이블 → 카드 전환 */
  .oms-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .oms-table-wrap table { min-width: 600px; }

  /* 드로어 풀스크린 */
  .ix-drawer {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 0 !important;
  }
  .ix-drawer .drawer-header { padding: 12px 16px !important; }
  .ix-drawer .drawer-body { padding: 12px 16px !important; }

  /* 모달 풀스크린 */
  .modal-content,
  .ix-modal-content {
    width: 95% !important;
    max-width: 95% !important;
    max-height: 85vh !important;
    margin: auto !important;
    border-radius: 12px !important;
  }
  
  /* 차트 영역 */
  .chart-container canvas { max-height: 200px; }

  /* 배치바 */
  .batch-bar, .ix-batch-bar {
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px) !important;
    left: 8px !important;
    right: 8px !important;
    border-radius: 12px !important;
  }

  /* 팝오버/컨텍스트메뉴 */
  .ix-popover, .context-menu { max-width: calc(100vw - 24px) !important; }

  /* 필터/액션바 가로 스크롤 */
  .filter-bar, .action-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    gap: 6px !important;
  }
  .filter-bar > *, .action-bar > * { flex-shrink: 0; }

  /* 텍스트 크기 조정 */
  .page-title { font-size: 18px !important; }
  .stat-card .stat-value { font-size: 20px !important; }

  /* ─── 주문 테이블 모바일 최적화 ─── */
  /* 모바일에서 주소, 주문번호, 지역법인, 팀장, 요청일 컬럼 숨김 */
  table thead th:nth-child(3), /* 주문번호 */
  table thead th:nth-child(5), /* 주소 */
  table thead th:nth-child(7), /* 지역법인 */
  table thead th:nth-child(8), /* 팀장 */
  table thead th:nth-child(10), /* 요청일 */
  table thead th:nth-child(11), /* 진행 */
  table tbody td:nth-child(3),
  table tbody td:nth-child(5),
  table tbody td:nth-child(7),
  table tbody td:nth-child(8),
  table tbody td:nth-child(10),
  table tbody td:nth-child(11) {
    display: none !important;
  }
  table { min-width: unset !important; font-size: 12px; }
  table th, table td { padding: 6px 4px !important; }

  /* ─── 칸반 모바일 최적화 ─── */
  .kanban-board {
    flex-direction: column !important;
    gap: 0 !important;
  }
  .kanban-column {
    width: 100% !important;
    min-width: 100% !important;
    min-height: auto !important;
    max-height: none !important;
  }
  .kanban-column.kanban-collapsed {
    min-height: 40px !important;
  }
  .kanban-column .kanban-body {
    max-height: 300px;
    overflow-y: auto;
  }

  /* 칸반 카드 터치 최적화 */
  .kanban-card {
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
  }

  /* ─── 필터 영역 가로 스크롤 ─── */
  .flex.gap-3.items-center.flex-wrap {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  
  /* ─── 버튼 터치 영역 확대 ─── */
  button, [onclick], a[href] {
    min-height: 36px;
  }
  
  /* ─── 검수 카드 ─── */
  .review-card, .settlement-card { margin-bottom: 8px; }

  /* ─── 통계 페이지 ─── */
  .stat-grid { grid-template-columns: 1fr !important; }

  /* ─── 가입 위자드 스텝 표시 ─── */
  .wizard-steps { font-size: 10px; gap: 4px !important; }
  .wizard-steps .step-label { display: none; }
}

/* ─── 태블릿 (769px ~ 1024px) ─── */
@media (min-width: 769px) and (max-width: 1024px) {
  .desktop-sidebar { width: 200px !important; }
  .desktop-sidebar .sidebar-item span { font-size: 13px; }
  
  .grid.grid-cols-4 { grid-template-columns: repeat(2, 1fr) !important; }
  
  .ix-drawer { max-width: 400px !important; }
}

/* ─── 데스크탑 (769px 이상): 모바일 요소 숨김 ─── */
@media (min-width: 769px) {
  .mobile-header { display: none !important; }
  .bottom-nav { display: none !important; }
}

/* ─── 애니메이션 ─── */
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ─── 풀투리프레시 ─── */
.ptr-indicator {
  position: fixed;
  top: var(--mobile-header-h);
  left: 50%;
  transform: translateX(-50%) translateY(-50px);
  width: 36px; height: 36px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 35;
  transition: transform 0.2s;
  pointer-events: none;
}
.ptr-indicator.active { transform: translateX(-50%) translateY(8px); }
.ptr-indicator i { color: #2563eb; font-size: 16px; }
.ptr-indicator.refreshing i { animation: spin 0.8s linear infinite; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── 스와이프 액션 ─── */
.swipe-container {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
}
.swipe-content {
  transition: transform 0.2s ease-out;
}
.swipe-actions {
  position: absolute;
  top: 0; bottom: 0;
  display: flex;
  align-items: stretch;
}
.swipe-actions-right { right: 0; transform: translateX(100%); }
.swipe-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  color: white;
  font-size: 12px;
  flex-direction: column;
  gap: 2px;
  border: none;
  cursor: pointer;
}
.swipe-action-btn.approve { background: #22c55e; }
.swipe-action-btn.reject { background: #ef4444; }
.swipe-action-btn.assign { background: #3b82f6; }
.swipe-action-btn i { font-size: 16px; }
