/**
 * Mobile Pro — Professional Mobile UI/UX System
 * ============================================== 
 * Upgraded: 2026-06-26 | Version 2.0.0
 * Advanced mobile-first design for USAHAKAN DIGITAL
 * Fixes overflow, improves touch interactions, professional styling
 */

/* =============================================
   GLOBAL OVERFLOW PREVENTION
   ============================================= */
html {
  overflow-x: hidden;
  width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
  width: 100%;
  position: relative;
}

* {
  -webkit-tap-highlight-color: transparent;
}

.overflow-guard {
  overflow-x: hidden;
  max-width: 100vw;
  position: relative;
}

/* =============================================
   MOBILE NAVIGATION — Improved
   ============================================= */
@media (max-width: 1023px) {
  /* Mobile drawer */
  .mobile-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(85%, 380px);
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 9999;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-drawer.open {
    transform: translateX(0);
  }

  /* Drawer backdrop */
  .drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: all 280ms ease;
    z-index: 9998;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
  }

  .drawer-backdrop.active {
    opacity: 1;
    visibility: visible;
  }

  /* Sticky mobile navbar */
  #mainNav {
    background: rgba(255, 255, 255, 0.96) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 1px 0 rgba(0,0,0,0.06), 0 2px 12px rgba(0,0,0,0.04) !important;
  }
}


/* =============================================
   MOBILE TOUCH IMPROVEMENTS
   ============================================= */
@media (max-width: 767px) {
  /* Ensure minimum touch target size */
  button, [role="button"], a,
  input[type="submit"], input[type="button"],
  label[for] {
    min-height: 44px;
  }

  /* Prevent tiny tappable areas */
  .bottom-nav-item { min-width: 44px; }

  /* Form inputs — prevent iOS auto zoom */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  input[type="date"],
  input[type="time"],
  select, textarea {
    font-size: 16px !important;
  }

  /* Reduce excessive padding on mobile */
  .container-mobile { padding-left: 14px !important; padding-right: 14px !important; }

  /* Compact headings on mobile */
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
}


/* =============================================
   MOBILE CONTENT PADDING
   ============================================= */
@media (max-width: 767px) {
  /* Account for bottom nav */
  .page-content-mobile { padding-bottom: 78px; }

  /* Account for fixed top bar */
  .has-topbar { padding-top: 64px; }
}


/* =============================================
   MOBILE CARD — Improved
   ============================================= */
@media (max-width: 639px) {
  /* Full-bleed card on mobile */
  .card-mobile-full {
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
    margin-left: -14px;
    margin-right: -14px;
  }

  /* Compact card padding */
  .card-compact { padding: 12px 14px !important; }

  /* Stack horizontal layouts */
  .flex-row-mobile { flex-direction: column !important; }

  /* Full width buttons on mobile */
  .btn-mobile-full { width: 100% !important; }
}


/* =============================================
   TABLE — Mobile Responsive
   ============================================= */
.ush-table-wrap,
.sni-table-container {
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

@media (max-width: 639px) {
  /* Table cell compact */
  .ush-table th { padding: 8px 12px; font-size: 0.6rem; }
  .ush-table td { padding: 10px 12px; font-size: 0.78rem; }
  .sni-table th { padding: 8px 12px; font-size: 0.6rem; }
  .sni-table td { padding: 10px 12px; font-size: 0.78rem; }
}


/* =============================================
   IMPROVED MOBILE GRID
   ============================================= */
@media (max-width: 479px) {
  /* Force 2-col on very small screens */
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
}

@media (max-width: 359px) {
  /* Force 1-col on tiny screens (320px) */
  .stat-grid-xs-1 { grid-template-columns: 1fr !important; }
}


/* =============================================
   MOBILE SIDEBAR TOGGLE BUTTON
   ============================================= */
.mobile-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(226, 232, 240, 0.8);
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn:hover,
.mobile-menu-btn:active { background: #f1f5f9; }


/* =============================================
   IMPROVED SCROLL SNAP (Horizontal carousels)
   ============================================= */
.snap-scroll-x {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.snap-scroll-x::-webkit-scrollbar { display: none; }

.snap-scroll-x > * {
  flex-shrink: 0;
  scroll-snap-align: start;
}


/* =============================================
   STAT CARD — Mobile Compact
   ============================================= */
@media (max-width: 639px) {
  .ush-stat-card { padding: 12px 14px; }
  .ush-stat-card .stat-value { font-size: 1.25rem; }
  .ush-stat-card .stat-label { font-size: 0.65rem; }
}


/* =============================================
   MODAL — Mobile Bottom Sheet
   ============================================= */
@media (max-width: 639px) {
  .ush-modal {
    border-radius: 20px 20px 0 0 !important;
    max-height: 88vh !important;
  }

  .ush-modal-body { padding: 16px; }
  .ush-modal-header { padding: 14px 16px 10px; }
  .ush-modal-footer { padding: 10px 16px 14px; flex-direction: column; }
  .ush-modal-footer .btn-primary,
  .ush-modal-footer .btn-ghost { width: 100% !important; }

  /* Modal drag handle indicator */
  .ush-modal::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 9999px;
    background: #E2E8F0;
    margin: 10px auto -2px;
  }
}


/* =============================================
   BOTTOM NAV — Enhanced safe area
   ============================================= */
.bottom-nav {
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 2px);
}

/* Ensure content doesn't get cut by bottom nav */
@media (max-width: 767px) {
  main, .main-content, #main-content-shell {
    padding-bottom: 70px;
  }
}


/* =============================================
   SIDEBAR — Mobile Animation
   ============================================= */
@media (max-width: 767px) {
  #sidebar-v2 {
    transform: translateX(-100%);
    transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  #sidebar-v2.flex {
    transform: translateX(0) !important;
  }

  #sidebar-v2.hidden {
    transform: translateX(-100%) !important;
  }
}


/* =============================================
   PRODUCT GRID — Mobile Optimized
   ============================================= */
@media (max-width: 479px) {
  /* 2 columns on small mobile */
  .product-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .prod-card .prod-img { aspect-ratio: 1 !important; }
}


/* =============================================
   FORM — Mobile Improvements
   ============================================= */
@media (max-width: 639px) {
  /* Stack label+input more tightly */
  .form-group { margin-bottom: 12px; }
  .form-label { margin-bottom: 4px; }

  /* Full-width select on mobile */
  .form-select { width: 100%; }

  /* Compact numpad */
  .numpad-btn, .numpad-btn-action { height: 52px; }
}


/* =============================================
   FILTER BAR — Horizontal scroll on mobile
   ============================================= */
@media (max-width: 639px) {
  .ush-filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .ush-filter-bar::-webkit-scrollbar { display: none; }
  .ush-filter-chip { flex-shrink: 0; }
}


/* =============================================
   TYPOGRAPHY — Mobile Scale
   ============================================= */
@media (max-width: 639px) {
  .page-title { font-size: 1.1rem; }
  .page-subtitle { font-size: 0.74rem; }
}


/* =============================================
   IMAGE — Prevent stretch on mobile
   ============================================= */
img { max-width: 100%; height: auto; }
.img-cover { object-fit: cover; width: 100%; }


/* =============================================
   PRINT — Hide nav elements
   ============================================= */
@media print {
  #sidebar-v2, .bottom-nav, #mainNav { display: none !important; }
  body { padding: 0 !important; }
}
