/* ============================================================
   ABUTECH RESPONSIVE ARCHITECTURE v2.0
   Auto Device Detection + 350px Mobile Constraint + Desktop
   ============================================================ */

/* ── CSS Custom Properties for Responsive Tokens ─────────── */
:root {
  --mobile-max-width: 350px;
  --tablet-max-width: 768px;
  --desktop-max-width: 1280px;
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --header-height: 60px;
  --bottom-nav-height: 70px;
}

/* ── Base Reset & Overrides ──────────────────────────────── */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
img, video { max-width: 100%; height: auto; }
table { border-collapse: collapse; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ── Device Detection Classes (set by device-detect.js) ──── */

/* ================================================================
   MOBILE LAYOUT (max-width: 480px)
   Forces app-like experience with 350px max-width container
   ================================================================ */
@media (max-width: 480px) {
  /* Force 350px width on mobile for the entire site */
  body[data-device="mobile"],
  body.is-mobile {
    max-width: var(--mobile-max-width) !important;
    margin-left: auto !important;
    margin-right: auto !important;
    position: relative;
    box-shadow: 0 0 50px rgba(0,0,0,0.5);
    background: var(--bg, #000);
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* App Container / Responsive Wrap (as fallback) */
  .app-container,
  .responsive-wrap {
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Force full width for nested containers */
  body[data-device="mobile"] .max-w-7xl,
  body[data-device="mobile"] .max-w-4xl,
  body[data-device="mobile"] .max-w-3xl,
  body[data-device="mobile"] .max-w-2xl,
  body[data-device="mobile"] .max-w-md {
    max-width: 100% !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Typography scaling */
  body[data-device="mobile"] h1,
  body[data-device="mobile"] .text-5xl,
  body[data-device="mobile"] .text-6xl,
  body[data-device="mobile"] .text-7xl {
    font-size: 1.75rem !important;
    line-height: 2.1rem !important;
  }
  body[data-device="mobile"] h2,
  body[data-device="mobile"] .text-4xl {
    font-size: 1.5rem !important;
    line-height: 1.9rem !important;
  }
  body[data-device="mobile"] .text-3xl {
    font-size: 1.25rem !important;
    line-height: 1.6rem !important;
  }
  body[data-device="mobile"] .text-2xl {
    font-size: 1.1rem !important;
    line-height: 1.5rem !important;
  }

  /* Spacing compression */
  body[data-device="mobile"] .p-6 { padding: 0.875rem !important; }
  body[data-device="mobile"] .p-8 { padding: 1rem !important; }
  body[data-device="mobile"] .p-10 { padding: 1.25rem !important; }
  body[data-device="mobile"] .px-6 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
  body[data-device="mobile"] .px-8 { padding-left: 1rem !important; padding-right: 1rem !important; }
  body[data-device="mobile"] .py-14 { padding-top: 2.5rem !important; padding-bottom: 2.5rem !important; }
  body[data-device="mobile"] .py-20 { padding-top: 3rem !important; padding-bottom: 3rem !important; }
  body[data-device="mobile"] .py-24 { padding-top: 3.5rem !important; padding-bottom: 3.5rem !important; }
  body[data-device="mobile"] .gap-6 { gap: 0.75rem !important; }
  body[data-device="mobile"] .gap-8 { gap: 1rem !important; }
  body[data-device="mobile"] .gap-12 { gap: 1.5rem !important; }
  body[data-device="mobile"] .gap-16 { gap: 2rem !important; }
  body[data-device="mobile"] .mb-8 { margin-bottom: 1.25rem !important; }
  body[data-device="mobile"] .mb-12 { margin-bottom: 1.5rem !important; }
  body[data-device="mobile"] .mb-16 { margin-bottom: 2rem !important; }

  /* Grid — force single column on mobile */
  body[data-device="mobile"] .grid.md\:grid-cols-2,
  body[data-device="mobile"] .grid.md\:grid-cols-3,
  body[data-device="mobile"] .grid.lg\:grid-cols-3,
  body[data-device="mobile"] .grid.lg\:grid-cols-4,
  body[data-device="mobile"] .grid.lg\:grid-cols-5,
  body[data-device="mobile"] .grid.md\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }
  body[data-device="mobile"] .grid.grid-cols-2 {
    grid-template-columns: 1fr 1fr !important;
  }
  body[data-device="mobile"] .grid.grid-cols-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  body[data-device="mobile"] .grid.grid-cols-2.md\:grid-cols-4.lg\:grid-cols-8 {
    grid-template-columns: repeat(4, 1fr) !important;
  }

  /* Hide desktop-only elements */
  body[data-device="mobile"] .desktop-only,
  body[data-device="mobile"] .hidden-mobile {
    display: none !important;
  }
  /* Show mobile-only elements */
  body[data-device="mobile"] .mobile-only {
    display: block !important;
  }

  /* Buttons — full width on mobile */
  body[data-device="mobile"] .btn {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
  }

  /* Cards — compressed */
  body[data-device="mobile"] .card {
    border-radius: 0.75rem;
  }

  /* Tables — horizontal scroll wrapper */
  body[data-device="mobile"] .overflow-x-auto {
    -webkit-overflow-scrolling: touch;
  }
  body[data-device="mobile"] table {
    font-size: 0.8rem;
  }
  body[data-device="mobile"] table th,
  body[data-device="mobile"] table td {
    padding: 0.5rem 0.625rem !important;
    white-space: nowrap;
  }

  /* Sticky Mobile Header */
  body[data-device="mobile"] .app-header-mobile {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.08);
  }

  /* Bottom Nav */
  body[data-device="mobile"] .bottom-nav-mobile {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: var(--safe-area-bottom);
    border-top: 1px solid rgba(255,255,255,0.08);
    z-index: 1000;
  }

  /* Footer padding for bottom nav */
  body[data-device="mobile"] footer,
  body[data-device="mobile"] .footer-spacer {
    padding-bottom: calc(var(--bottom-nav-height) + 20px) !important;
  }

  /* Sidebar — slide overlay on mobile */
  body[data-device="mobile"] .sidebar-desktop {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    z-index: 999 !important;
    width: 280px !important;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
  }
  body[data-device="mobile"] .sidebar-desktop.sidebar-open {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  body[data-device="mobile"] .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 998;
  }
  body[data-device="mobile"] .sidebar-overlay.active {
    display: block;
  }

  /* Stat cards — compact */
  body[data-device="mobile"] .stat-card {
    padding: 0.875rem !important;
  }
  body[data-device="mobile"] .stat-card .text-3xl {
    font-size: 1.25rem !important;
  }

  /* Admin Quick Actions — 2-col on mobile */
  body[data-device="mobile"] .admin-actions-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Charts — reduce height on mobile */
  body[data-device="mobile"] .h-80 {
    height: 200px !important;
  }

  /* Form inputs — larger touch targets */
  body[data-device="mobile"] input[type="text"],
  body[data-device="mobile"] input[type="email"],
  body[data-device="mobile"] input[type="password"],
  body[data-device="mobile"] input[type="tel"],
  body[data-device="mobile"] input[type="number"],
  body[data-device="mobile"] select,
  body[data-device="mobile"] textarea {
    min-height: 44px;
    font-size: 16px !important; /* Prevents iOS zoom */
  }

  /* Navigation bar — mobile compact */
  body[data-device="mobile"] nav .flex.justify-between {
    padding: 0.5rem 0.75rem !important;
  }
  body[data-device="mobile"] nav .h-16 {
    height: auto !important;
    min-height: 52px;
  }
}

/* ── Extra narrow (350px and below) ──────────────────────── */
@media (max-width: 360px) {
  body[data-device="mobile"] .grid.grid-cols-2 {
    grid-template-columns: 1fr !important;
  }
  body[data-device="mobile"] .flex-wrap { 
    flex-direction: column !important;
  }
  body[data-device="mobile"] .text-xl {
    font-size: 1rem !important;
  }
  body[data-device="mobile"] .text-lg {
    font-size: 0.9rem !important;
  }
}


/* ================================================================
   TABLET LAYOUT (481px – 1024px)
   ================================================================ */
@media (min-width: 481px) and (max-width: 1024px) {
  .mobile-only { display: none !important; }
  
  body[data-device="tablet"] .max-w-7xl {
    max-width: 100%;
    padding-left: 24px;
    padding-right: 24px;
  }
  
  body[data-device="tablet"] .grid.lg\:grid-cols-4,
  body[data-device="tablet"] .grid.lg\:grid-cols-5 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  body[data-device="tablet"] .grid.lg\:grid-cols-3 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}


/* ================================================================
   DESKTOP LAYOUT (1025px+)
   Enforced desktop-optimized experience
   ================================================================ */
@media (min-width: 1025px) {
  .mobile-only { display: none !important; }
  
  body[data-device="desktop"] .desktop-only {
    display: flex !important;
  }

  /* Ensure proper max-widths on desktop */
  body[data-device="desktop"] .max-w-7xl {
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
  }

  /* Sidebar — always visible on desktop */
  body[data-device="desktop"] .sidebar-desktop {
    position: static !important;
    transform: none !important;
    width: 260px !important;
  }
  body[data-device="desktop"] .sidebar-overlay {
    display: none !important;
  }

  /* Desktop hover enhancements */
  body[data-device="desktop"] .card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.15);
  }
  body[data-device="desktop"] .stat-card:hover {
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
  }

  /* Admin nav — full horizontal */
  body[data-device="desktop"] .admin-nav-items {
    display: flex !important;
  }
}


/* ================================================================
   SHARED UTILITIES
   ================================================================ */

/* Smooth transitions for responsive changes */
.responsive-transition {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Mobile-only / Desktop-only defaults */
.mobile-only { display: none; }
.desktop-only { display: flex; }

/* Table responsive wrapper */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0.75rem;
}

/* Admin Layout — responsive flex */
.admin-layout {
  display: flex;
  min-height: 100vh;
}
.admin-content {
  flex: 1;
  overflow-x: hidden;
}

/* Scroll entrance animation (shared) */
.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}
.reveal.active {
  opacity: 1;
  transform: translateY(0);
}

/* Mobile hamburger button */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(10px);
  color: inherit;
}
@media (max-width: 480px) {
  .mobile-menu-btn { display: flex; }
}
@media (min-width: 1025px) {
  .mobile-menu-btn { display: none !important; }
}

/* Print — hide nav elements */
@media print {
  .bottom-nav-mobile, .app-header-mobile, .mobile-menu-btn, nav { display: none !important; }
  body { font-size: 12pt; }
}
