/* ═══ CANEX ERP — Mobile Enhancement ═══ */
/* Bổ sung cho mobile UX, KHÔNG override CSS gốc */

/* ── 768px: Smartphone ── */
@media (max-width: 768px) {
  /* ═══ DASHBOARD COMPACT ═══ */
  
  /* Hero gọn thêm */
  .dash-hero {
    padding: 12px 14px;
    margin-bottom: 8px;
    border-radius: 12px;
  }

  .dash-hero-title {
    font-size: 17px;
    gap: 6px !important;
  }

  .dash-hero-sub {
    font-size: 11px;
    margin-top: 4px;
  }

  .dash-hero-tag {
    font-size: 11px;
    padding: 2px 8px;
  }

  /* Stats margin */
  .dash-stats {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
    margin-bottom: 8px !important;
  }

  .stat-card {
    padding: 10px 12px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .stat-card-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
    margin-bottom: 0;
  }

  .stat-card-icon svg {
    width: 16px !important;
    height: 16px !important;
  }

  .stat-card-value {
    font-size: 18px;
    margin-bottom: 0;
    line-height: 1.1;
  }

  .stat-card-label {
    font-size: 10px;
    line-height: 1.2;
  }

  .stat-card-change {
    font-size: 9px;
  }

  /* Progress bar trong stat card gọn */
  .stat-card .progress-bar {
    margin-top: 4px;
  }

  /* Dash grid: 1 col, tight */
  .dash-grid {
    gap: 6px !important;
  }

  /* Cards trong dashboard gọn */
  .dash-grid > .card {
    padding: 10px 12px;
    border-radius: 10px;
  }

  .dash-grid .card-header {
    margin-bottom: 6px;
  }

  .dash-grid .card-title {
    font-size: 13px;
  }

  /* Pie chart + legend nằm gọn */
  .dash-grid .card:first-child > div:last-child {
    gap: 12px !important;
    flex-direction: row;
    align-items: center;
  }

  /* Activity list compact */
  .dash-grid .card:nth-child(2) > div:last-child {
    max-height: 200px !important;
  }

  /* Deadline card — ẩn empty state icon to, giữ text gọn */
  .dash-grid .card:nth-child(4) .empty-state,
  .dash-grid .card:last-child .empty-state {
    padding: 12px 0;
  }

  .dash-grid .card:nth-child(4) .empty-state-icon,
  .dash-grid .card:last-child .empty-state-icon {
    font-size: 28px;
    margin-bottom: 4px;
  }

  .dash-grid .card:nth-child(4) .empty-state-desc,
  .dash-grid .card:last-child .empty-state-desc {
    font-size: 12px;
  }

  /* Empty state chung — gọn trên mobile */
  .empty-state {
    padding: 10px 0 !important;
    min-height: 0 !important;
  }

  .empty-state-icon {
    font-size: 24px !important;
    margin-bottom: 2px !important;
    width: auto !important;
    height: auto !important;
  }

  /* Ẩn emoji icon to trong empty state, chỉ giữ text */
  .empty-state-icon img,
  .empty-state-icon svg {
    width: 28px !important;
    height: 28px !important;
  }

  .empty-state-title {
    font-size: 13px;
  }

  .empty-state-desc {
    font-size: 12px;
  }

  /* Deadline card khi trống — minimal, 1 dòng */
  .dash-grid > .card:last-child {
    padding: 10px 12px;
  }

  .dash-grid > .card:last-child .empty-state {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 4px 0 !important;
  }

  .dash-grid > .card:last-child .empty-state-icon {
    font-size: 20px !important;
    margin-bottom: 0 !important;
  }
  
  /* Page content tighter */
  .page-content {
    padding: 10px !important;
    padding-top: calc(var(--topbar-h) + 10px) !important;
    padding-bottom: calc(var(--bottom-nav-h) + 10px) !important;
  }

  /* Toast notifications không che hero */
  .Toastify__toast-container,
  [class*="toast-container"],
  [class*="Toaster"] {
    top: calc(var(--topbar-h) + 4px) !important;
    font-size: 12px;
  }

  /* Activity items tighter */
  .dash-activity-item {
    padding: 6px 0;
    gap: 8px;
  }

  .dash-activity-icon {
    font-size: 14px;
    width: 28px;
    height: 28px;
    min-width: 28px;
  }

  .dash-activity-text {
    font-size: 12px;
    line-height: 1.3;
  }

  .dash-activity-time {
    font-size: 10px;
  }

  /* Deadline items compact */
  .dash-deadline-item {
    padding: 6px 0;
  }

  .dash-deadline-item div:first-child div:first-child {
    font-size: 12px !important;
  }

  .dash-deadline-item div:first-child div:last-child {
    font-size: 10px !important;
  }

  /* Ẩn biểu đồ cột trên mobile — thông tin trùng với pie chart */
  .dash-grid > .card:nth-child(3) {
    display: none;
  }

  /* ═══ TASK PANEL FULL SCREEN ═══ */
  .task-panel > div:last-child,
  .task-panel > div:not(.task-panel-overlay) {
    width: 100vw !important;
    max-width: 100vw !important;
    border-radius: 0 !important;
  }

  .task-panel-header {
    padding: 14px 16px;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10;
  }

  .task-panel-body {
    padding: 16px;
  }

  .task-panel-section {
    margin-bottom: 16px;
  }

  /* ═══ CONTRACT CARDS ═══ */
  .contract-card {
    padding: 14px;
  }

  .contract-card-title {
    font-size: 14px;
  }

  .contract-card-stats {
    gap: 8px;
    flex-wrap: wrap;
  }

  .contract-card-stat {
    font-size: 11px;
  }

  /* ═══ TREE VIEW MOBILE FIX ═══ */

  /* Tree header - contract info */
  .tree-header {
    margin-bottom: 12px;
  }

  .tree-header-title {
    font-size: 16px;
    word-break: break-word;
  }

  .tree-header-meta {
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
  }

  /* Tabs/filters scroll horizontal */
  .tree-toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    gap: 4px;
    padding-bottom: 4px;
  }

  .tree-toolbar::-webkit-scrollbar {
    display: none;
  }

  .tree-toolbar .btn,
  .tree-toolbar > * {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 11px;
    padding: 5px 8px;
  }

  /* Filter tabs row */
  .tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 2px;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 11px;
    padding: 5px 10px;
  }

  /* Phase header - prevent overflow */
  .tree-phase-header {
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .tree-phase-title {
    font-size: 13px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tree-phase-stats {
    font-size: 11px;
    gap: 4px;
  }

  /* Task rows - prevent text overflow */
  .tree-task {
    padding: 8px 10px;
    gap: 6px;
    overflow: hidden;
  }

  .tree-task-title {
    font-size: 12px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tree-task-meta {
    flex-shrink: 0;
    gap: 4px;
    max-width: 45%;
    justify-content: flex-end;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .tree-task-meta .badge {
    font-size: 9px;
    padding: 1px 6px;
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tree-task-meta .avatar-xs,
  .tree-task-meta > span:not(.badge) {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60px;
  }

  /* Phase body less padding */
  .tree-phase-body {
    padding: 4px 6px 8px;
  }

  /* Add button (+) at the end of phase header */
  .tree-phase-header .btn-icon,
  .tree-phase-header > button:last-child {
    width: 28px;
    height: 28px;
    min-width: 28px;
    flex-shrink: 0;
  }

  /* Prevent horizontal scroll on the whole page */
  .page-content {
    overflow-x: hidden !important;
  }

  /* Contract detail header */
  .contract-detail-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .contract-detail-actions {
    gap: 4px;
  }

  .contract-detail-actions .btn-icon {
    width: 30px;
    height: 30px;
  }

  /* Kanban - smaller columns */
  .kanban-board {
    padding-bottom: 12px;
  }

  .kanban-column {
    flex: 0 0 220px;
  }

  /* Buttons mobile-friendly */
  .btn {
    min-height: 38px;
    font-size: 13px;
  }

  .btn-sm {
    min-height: 32px;
    padding: 4px 10px;
    font-size: 12px;
  }

  /* Badges smaller */
  .badge {
    font-size: 10px;
    padding: 2px 8px;
  }

  /* Tabs scrollable */
  .tabs {
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 2px;
    margin-bottom: 14px;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tab {
    padding: 7px 12px;
    font-size: 12px;
  }

  /* Table touch scroll */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  /* Document items stack */
  .doc-item {
    padding: 10px;
  }

  .doc-name {
    font-size: 13px;
  }

  .doc-meta {
    font-size: 11px;
  }

  /* Checklist touch targets */
  .checklist-item {
    min-height: 44px;
    padding: 10px 0;
  }

  /* Chat mobile */
  .chat-message {
    max-width: 88%;
  }

  .chat-input-wrap {
    padding: 8px 0;
  }

  /* Activity items */
  .dash-activity-item {
    padding: 10px 0;
    gap: 10px;
  }

  /* Notifications dropdown fullwidth */
  .notif-dropdown {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    width: 100vw;
    max-height: 70vh;
    border-radius: 0 0 16px 16px;
  }

  /* Modal full-screen on mobile */
  .modal > div {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: 90vh;
    margin: 12px;
  }

  /* Page content spacing */
  .page-content {
    padding: 12px;
    padding-top: calc(var(--topbar-h) + 12px);
    padding-bottom: calc(var(--bottom-nav-h) + 12px);
  }

  .page-title {
    font-size: 18px;
    margin-bottom: 12px;
  }

  /* Kanban horizontal scroll */
  .kanban-column {
    flex: 0 0 240px;
  }

  /* Admin user list */
  .admin-user-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Report charts */
  .report-charts {
    grid-template-columns: 1fr;
  }

  /* Reduce general spacing */
  .card {
    padding: 14px;
    border-radius: 12px;
  }

  .card-header {
    margin-bottom: 12px;
  }

  .card-title {
    font-size: 14px;
  }

  /* Search modal */
  .search-modal {
    width: calc(100vw - 24px);
    margin: 12px;
  }

  /* Topbar clean */
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  /* Bottom nav items bigger touch */
  .bottom-nav-item {
    padding: 6px 12px;
    min-width: 48px;
  }
}

/* ── 480px: Small phones ── */
@media (max-width: 480px) {
  .dash-hero {
    padding: 12px;
    border-radius: 10px;
  }

  .dash-hero-title {
    font-size: 16px;
  }

  .dash-stats {
    gap: 6px !important;
  }

  .stat-card {
    padding: 10px;
  }

  .stat-card-value {
    font-size: 18px;
  }

  .stat-card-icon {
    width: 28px;
    height: 28px;
    margin-bottom: 4px;
  }

  .stat-card-icon svg {
    width: 14px !important;
    height: 14px !important;
  }

  .stat-card-label {
    font-size: 9px;
  }

  /* Ẩn luôn biểu đồ tròn trên phone nhỏ — chỉ giữ activity + deadline */
  .dash-grid > .card:nth-child(1) {
    display: none;
  }

  .contract-card {
    padding: 12px;
  }

  .contract-card-title {
    font-size: 13px;
  }

  .tree-task {
    padding: 8px 10px;
  }

  .tree-phase-header {
    padding: 10px 12px;
  }

  .page-content {
    padding: 8px;
    padding-top: calc(var(--topbar-h) + 8px);
    padding-bottom: calc(var(--bottom-nav-h) + 8px);
  }

  .task-panel-body {
    padding: 12px;
  }

  .task-panel-actions .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
  }

  .modal > div {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    margin: 8px;
  }

  .bottom-nav-item {
    font-size: 9px;
    padding: 4px 8px;
  }

  .bottom-nav-item svg {
    width: 18px;
    height: 18px;
  }
}

/* ── Touch device improvements ── */
@media (hover: none) and (pointer: coarse) {
  /* Bigger touch targets */
  .tree-task,
  .checklist-item,
  .doc-item,
  .dash-activity-item {
    min-height: 44px;
  }

  .btn, .tab, .bottom-nav-item {
    min-height: 40px;
  }

  /* Active state thay vì hover */
  .contract-card:active,
  .tree-task:active,
  .card:active {
    transform: scale(0.98);
    opacity: 0.9;
  }

  .btn:active {
    transform: scale(0.95);
    opacity: 0.85;
  }

  /* Disable hover effects */
  .contract-card:hover,
  .tree-task:hover,
  .card:hover {
    transform: none;
    box-shadow: none;
  }
}

/* ── Safe area cho iPhone notch ── */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    .bottom-nav {
      padding-bottom: env(safe-area-inset-bottom);
      height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    }

    .page-content {
      padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 8px);
    }
  }
}

/* ── Landscape phone ── */
@media (max-height: 500px) and (orientation: landscape) {
  .bottom-nav {
    height: 48px;
  }

  .page-content {
    padding-bottom: 56px;
  }
}
