/* ═══════════════════════════════════════════════════════════════════
   PING V3 — PREMIUM MOBILE RESPONSIVE OVERRIDES & TOUCH ARCHITECTURE
   Target: Viewports < 768px (CSS Cascade Overrides)
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 767.98px) {
  /* ────────────────────────────────────────────────────────────────
     1. GLOBAL SIDEBAR DRAWER & TRANSLUCENT BACKDROP & TOP HEADER
     ──────────────────────────────────────────────────────────────── */
  
  /* App layout override */
  .app-shell {
    grid-template-columns: 1fr !important;
    padding-top: 56px !important; /* Make room for sticky glassmorphic mobile header */
  }

  /* Off-canvas sidebar configuration */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(84vw, 300px) !important;
    height: 100vh !important;
    z-index: 2000 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    box-shadow: 20px 0 40px rgba(0, 0, 0, 0.4) !important;
    border-radius: 0 16px 16px 0 !important;
  }

  /* Body states to toggle drawer open */
  body.sidebar-open .sidebar,
  .sidebar.open {
    transform: translateX(0) !important;
  }

  /* Translucent backdrop styles */
  .sidebar-backdrop,
  .mobile-sidebar-backdrop {
    position: fixed !important;
    inset: 0 !important;
    background: rgba(6, 18, 37, 0.6) !important;
    backdrop-filter: blur(6px) !important;
    z-index: 1999 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.3s ease !important;
  }

  body.sidebar-open .sidebar-backdrop,
  body.sidebar-open .mobile-sidebar-backdrop {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Dark glassmorphic mobile top header bar */
  .mobile-header-bar,
  .mobile-top-bar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 56px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 0 16px !important;
    background: rgba(6, 18, 37, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border-bottom: 1px solid rgba(148, 184, 233, 0.18) !important;
    z-index: 999 !important;
    box-shadow: 0 4px 20px rgba(2, 8, 23, 0.3) !important;
  }

  .mobile-header-logo {
    font-size: 20px !important;
    font-weight: 700 !important;
    letter-spacing: -0.02em !important;
    color: #ffffff !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
  }

  /* Menu Toggle Button */
  .mobile-menu-toggle {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 38px !important;
    height: 38px !important;
    border-radius: 8px !important;
    border: 1px solid rgba(148, 184, 233, 0.25) !important;
    background: rgba(255, 255, 255, 0.05) !important;
    color: #ffffff !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
  }

  .mobile-menu-toggle:active {
    background: rgba(255, 255, 255, 0.15) !important;
    transform: scale(0.95) !important;
  }

  /* Hide mobile header elements on desktop */
  @media (min-width: 768px) {
    .mobile-header-bar,
    .mobile-top-bar {
      display: none !important;
    }
  }

  /* ────────────────────────────────────────────────────────────────
     2. EXECUTIVE DASHBOARD AUTO-FITTING KPI GRIDS & CARDS
     ──────────────────────────────────────────────────────────────── */
  
  .kpi-grid,
  .dashboard-grid,
  .stat-grid,
  .grid-cols-4,
  .grid-cols-3,
  .dashboard-top-metrics {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
    gap: 12px !important;
    padding: 4px 0 !important;
  }

  .dashboard-card,
  .stat-card,
  .premium-card {
    padding: 14px !important;
    margin-bottom: 12px !important;
    border-radius: 12px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Stack main content grid and charts */
  .dashboard-main-layout,
  .charts-grid,
  .dashboard-split {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* ────────────────────────────────────────────────────────────────
     3. TASKS LIST SPLIT WORKSPACE TRANSITIONS
     ──────────────────────────────────────────────────────────────── */
  
  /* Double column to single column workspace split */
  .tasks-split-workspace,
  .tasks-layout-container {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;
  }

  /* Tab-based routing visibility controls */
  .tasks-sidebar-column,
  .departments-column {
    display: none !important;
    width: 100% !important;
  }

  .tasks-list-column,
  .tasks-main-column {
    display: none !important;
    width: 100% !important;
  }

  /* Trigger single active view based on body state classes */
  body.show-departments .tasks-sidebar-column,
  body.show-departments .departments-column {
    display: block !important;
  }

  body.show-tasks .tasks-list-column,
  body.show-tasks .tasks-main-column {
    display: block !important;
  }

  /* Custom Floating Mobile Tab Controls */
  .mobile-workspace-tabs {
    display: flex !important;
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(0,0,0,0.06) !important;
    border-radius: 10px !important;
    padding: 4px !important;
    margin: 8px 0 16px 0 !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05) !important;
  }

  .mobile-tab-btn {
    flex: 1 !important;
    text-align: center !important;
    padding: 8px 12px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    border: none !important;
    background: transparent !important;
    border-radius: 7px !important;
    color: #5a6a80 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
  }

  .mobile-tab-btn.active {
    background: #2563eb !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(37,99,235,0.2) !important;
  }

  /* ────────────────────────────────────────────────────────────────
     4. NOTICES & CLIENTS TABLES TO CARDS TRANSFORMATION
     ──────────────────────────────────────────────────────────────── */
  
  .cl-table-card,
  .notices-table-card,
  .master-table-wrapper {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
  }

  .cl-table,
  .notices-table,
  .master-data-table {
    display: block !important;
    width: 100% !important;
    min-width: 100% !important;
  }

  /* Hide standard header */
  .cl-table thead,
  .notices-table thead,
  .master-data-table thead {
    display: none !important;
  }

  .cl-table tbody,
  .notices-table tbody,
  .master-data-table tbody {
    display: block !important;
    width: 100% !important;
  }

  /* Convert each row into a distinct glassmorphic card */
  .cl-table tbody tr,
  .notices-table tbody tr,
  .master-data-table tbody tr {
    display: block !important;
    width: 100% !important;
    background: #ffffff !important;
    border: 1px solid #e4eaf2 !important;
    border-radius: 12px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.03) !important;
    padding: 12px 16px !important;
    margin-bottom: 16px !important;
    box-sizing: border-box !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
  }

  .cl-table tbody tr:hover,
  .notices-table tbody tr:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06) !important;
  }

  /* Transform table cells into horizontal split metadata fields */
  .cl-table tbody td,
  .notices-table tbody td,
  .master-data-table tbody td {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 8px 0 !important;
    border-bottom: 1px solid #f1f5f9 !important;
    font-size: 13px !important;
    min-height: 40px !important;
    width: 100% !important;
    text-align: right !important;
    box-sizing: border-box !important;
  }

  .cl-table tbody td:first-child,
  .notices-table tbody td:first-child,
  .cl-table tbody td:last-child,
  .notices-table tbody td:last-child {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .cl-table tbody tr td:last-child,
  .notices-table tbody tr td:last-child,
  .master-data-table tbody tr td:last-child {
    border-bottom: none !important;
  }

  /* CSS label generation using data attributes or positions */
  .cl-table tbody td::before,
  .notices-table tbody td::before,
  .master-data-table tbody td::before {
    content: attr(data-label) !important;
    font-weight: 700 !important;
    color: #5a6a80 !important;
    font-size: 11px !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    text-align: left !important;
    float: left !important;
    padding-right: 12px !important;
  }

  /* Optimize name and special details in cells */
  .cl-name-cell,
  .cl-id-cell,
  .cl-act-cell {
    width: auto !important;
    text-align: right !important;
    align-items: flex-end !important;
  }

  .cl-act-cell {
    justify-content: flex-end !important;
  }

  .cl-client-name {
    font-size: 14px !important;
  }

  /* ────────────────────────────────────────────────────────────────
     5. DRAWERS & MODALS FULL VIEWPORT COVERS
     ──────────────────────────────────────────────────────────────── */
  
  .cl-drawer,
  .modal-panel,
  .drawer-panel,
  .tcr-modal,
  .modal-panel--task-create,
  [role="dialog"] {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    transform: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    position: fixed !important;
    display: flex !important;
    flex-direction: column !important;
    z-index: 2500 !important;
  }

  /* Ensure slide animation is clean or simple for mobile devices */
  .cl-drawer {
    transform: translateX(100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  .cl-drawer.open {
    transform: translateX(0) !important;
  }

  /* Single-column form layouts */
  .cl-form-grid,
  .grid-cols-2,
  .form-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .cl-span2,
  .col-span-2 {
    grid-column: span 1 !important;
  }

  /* Scrollable body content under full screen drawer header */
  .cl-drawer-body,
  .modal-body {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 16px !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Sticky Bottom Actions Footer */
  .cl-drawer-footer,
  .modal-footer,
  .form-actions {
    position: sticky !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    background: #ffffff !important;
    border-top: 1px solid #e4eaf2 !important;
    padding: 14px 16px !important;
    z-index: 100 !important;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08) !important;
    display: flex !important;
    gap: 10px !important;
    justify-content: flex-end !important;
    box-sizing: border-box !important;
  }

  .cl-drawer-footer button,
  .modal-footer button {
    flex: 1 !important;
    min-height: 42px !important;
  }

  /* ────────────────────────────────────────────────────────────────
     6. MOBILE HOVER FIXES & Tactile Tap Scaling
     ──────────────────────────────────────────────────────────────── */
  
  /* Disable sticky hover states on touch-enabled screens */
  @media (hover: none) {
    .cl-btn-primary:hover,
    .cl-btn-outline:hover,
    .sidebar-nav a:hover,
    .cl-kebab-btn:hover,
    .cl-pg-btn:hover {
      background-color: initial !important;
      color: initial !important;
      transform: none !important;
      box-shadow: none !important;
    }
  }

  /* tactile tap active response feedback */
  a:active,
  button:active,
  .btn:active,
  .cl-btn-primary:active,
  .cl-btn-outline:active,
  .sidebar-nav a:active,
  .cl-kebab-btn:active,
  .cl-pg-btn:active,
  .mobile-tab-btn:active {
    transform: scale(0.96) !important;
    transition: transform 0.05s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   SPA ROUTE TRANSITION SECTION GUARDS (Zero Flash FOUC Fix)
   ═══════════════════════════════════════════════════════════════════ */
/* Force hide pages that belong to a different section than the currently active body data-section attribute */
body[data-section="notices"] .tasks-page,
body[data-section="masters"] .tasks-page,
body[data-section="dashboard"] .tasks-page {
  display: none !important;
}

body[data-section="tasks"] .module-notices,
body[data-section="masters"] .module-notices,
body[data-section="dashboard"] .module-notices {
  display: none !important;
}

body[data-section="tasks"] .master-page,
body[data-section="notices"] .master-page,
body[data-section="dashboard"] .master-page {
  display: none !important;
}

body[data-section="tasks"] #dp-root,
body[data-section="notices"] #dp-root,
body[data-section="masters"] #dp-root {
  display: none !important;
}

