/*
  ImagineOS Mobile Core CSS (OS-v3)
  Unified Mobile UI Engine & Touch Ergonomics Standard
  Supports Web Apps (PWA) and Native Android Apps (TWA/Capacitor)
*/

/* --- 1. Touch Target & Mobile Ergonomics Standards --- */
@media (max-width: 768px) {
  :root {
    --mobile-nav-height: 64px;
    --touch-target-min: 48px;
    --side-padding: 16px;
  }

  /* Force minimum 48px touch targets for accessibility (WCAG AA/AAA) */
  button,
  .os-btn,
  .ed-btn,
  input[type="button"],
  input[type="submit"],
  select,
  .nav-link,
  .os-touch-target {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    padding-top: 12px;
    padding-bottom: 12px;
    font-size: 1rem;
    touch-action: manipulation;
  }

  /* Prevent text scaling bugs on Android Chrome */
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* --- 2. Adaptive Bento Grid Stacking --- */
  .ed-bento-grid,
  .os-bento-grid,
  .grid-cols-4,
  .grid-cols-3,
  .grid-cols-2,
  [class*="grid-cols-"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  .ed-card,
  .os-card {
    height: auto !important;
    margin-bottom: 12px;
  }

  /* Full-bleed mobile container paddings */
  .container,
  .main-content,
  main,
  section {
    padding-left: var(--side-padding) !important;
    padding-right: var(--side-padding) !important;
    max-width: 100vw !important;
  }

  /* --- 3. Datatable to Responsive Mobile Card Transformation --- */
  .os-table-responsive {
    display: block;
    width: 100%;
  }

  .os-table-responsive table,
  .os-table-responsive tbody,
  .os-table-responsive tr,
  .os-table-responsive td {
    display: block;
    width: 100%;
  }

  .os-table-responsive thead {
    display: none; /* Hide traditional table headers on mobile */
  }

  .os-table-responsive tr {
    background: var(--bg-card, #121826);
    border: 1px solid var(--border-card, rgba(255, 255, 255, 0.12));
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }

  .os-table-responsive td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    text-align: right;
  }

  .os-table-responsive td:last-child {
    border-bottom: none;
  }

  .os-table-responsive td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted, #94a3b8);
    text-align: left;
    padding-right: 12px;
  }

  /* --- 4. Mobile Bottom Navigation Bar (`.os-mobile-bottom-nav`) --- */
  .os-mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background: rgba(10, 13, 20, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 9999;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .os-mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted, #94a3b8);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 500;
    flex: 1;
    height: 100%;
    transition: color 0.2s ease;
  }

  .os-mobile-nav-item.active,
  .os-mobile-nav-item:hover {
    color: var(--accent-primary, #f59e0b);
  }

  .os-mobile-nav-item svg,
  .os-mobile-nav-item .icon {
    width: 22px;
    height: 22px;
    margin-bottom: 4px;
  }

  /* Offset body content so bottom nav doesn't hide page elements */
  body {
    padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Hide desktop-only sidebars when bottom nav is active */
  .desktop-sidebar,
  .ed-sidebar {
    display: none !important;
  }
}

/* Hide mobile-only elements on Desktop screens */
@media (min-width: 769px) {
  .os-mobile-bottom-nav,
  .mobile-only {
    display: none !important;
  }
}
