/* ====================================
   Mobile & Touch Optimizations
   Enhanced for mobile devices
   ==================================== */

/* ====================
   Touch Optimization
   ==================== */

/* Ensure touch targets are at least 44x44px */
button, a, input[type="button"], input[type="checkbox"], input[type="radio"] {
  min-height: 44px;
  min-width: 44px;
  padding: 12px 16px;
}

@media (min-width: 768px) {
  button, a, input[type="button"], input[type="checkbox"], input[type="radio"] {
    min-height: 40px;
    min-width: 40px;
    padding: 10px 14px;
  }
}

/* ====================
   Mobile Navigation Bar
   ==================== */

.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  display: flex;
  justify-content: space-around;
  align-items: center;
  gap: 0;
  background: rgba(15, 23, 42, 0.98);
  border-top: 1px solid rgba(148, 163, 184, 0.1);
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
  .mobile-nav {
    display: none;
  }
}

/* Mobile nav items */
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 10px;
  font-weight: 600;
  transition: all 0.2s;
  flex: 1;
}

.nav-item .icon {
  font-size: 1.5rem;
  line-height: 1;
}

.nav-item.active {
  color: #fe2c55;
}

.nav-item:active {
  transform: scale(0.95);
}

/* ====================
   Mobile Sidebar
   ==================== */

@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    width: 80%;
    max-width: 320px;
    height: 100vh;
    z-index: 1000;
    transition: left 0.3s ease;
    overflow-y: auto;
    padding-bottom: 80px;
  }
  
  .sidebar.open {
    left: 0;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  }
  
  .sidebar-nav {
    padding: 12px 0;
  }
}

/* ====================
   Mobile Page Content
   ==================== */

@media (max-width: 640px) {
  .page {
    padding: 16px 12px;
    padding-bottom: 100px;
  }
  
  /* Ensure full-width on mobile */
  .container, [class*="wrapper"] {
    max-width: 100%;
    padding: 0;
    margin: 0;
  }
  
  /* Better spacing for buttons */
  .btn, button, input[type="button"], .settings-button {
    padding: 12px 16px;
    font-size: 16px;
    border-radius: 10px;
    touch-action: manipulation;
  }
  
  /* Better form inputs */
  input, textarea, select {
    font-size: 16px;
    padding: 12px;
    border-radius: 10px;
    min-height: 44px;
  }
  
  /* Prevent zoom on input focus */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  textarea {
    font-size: 16px;
  }
}

/* ====================
   Horizontal Scroll (Mobile)
   ==================== */

@media (max-width: 768px) {
  /* Store tabs */
  .store-tabs,
  .store-controls {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
  
  /* Settings nav */
  .settings-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Category pills in feed */
  .category-pills {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Remove scrollbar visual but keep scroll */
  .store-tabs::-webkit-scrollbar,
  .settings-nav::-webkit-scrollbar,
  .category-pills::-webkit-scrollbar {
    height: 2px;
  }
  
  .store-tabs::-webkit-scrollbar-thumb,
  .settings-nav::-webkit-scrollbar-thumb,
  .category-pills::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 1px;
  }
}

/* ====================
   Modal/Dialog Mobile
   ==================== */

@media (max-width: 640px) {
  .modal, [role="dialog"] {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1001;
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
  }
  
  .modal-content, [role="dialog"] > div {
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
  }
}

/* ====================
   Landscape Orientation
   ==================== */

@media (max-height: 600px) and (orientation: landscape) {
  .mobile-nav {
    padding: 4px 0;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
  }
  
  .nav-item {
    padding: 4px 8px;
  }
  
  .nav-item .icon {
    font-size: 1.25rem;
  }
  
  .page {
    padding-bottom: 80px;
  }
}

/* ====================
   Gesture-Aware Styling
   ==================== */

@supports (padding: env(safe-area-inset-bottom)) {
  .mobile-nav,
  .sticky-bottom {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ====================
   Mobile Card Optimization
   ==================== */

@media (max-width: 640px) {
  .card, [class*="card"] {
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
  }
  
  .card-header {
    margin-bottom: 12px;
    padding-bottom: 8px;
  }
}

/* ====================
   Mobile Video Player
   ==================== */

@media (max-width: 640px) {
  .video-player, video {
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: auto;
  }
  
  .video-controls {
    gap: 8px;
    font-size: 12px;
  }
}

/* ====================
   Mobile Avatar/Image Optimization
   ==================== */

@media (max-width: 640px) {
  .avatar, [class*="avatar"] {
    width: 40px;
    height: 40px;
  }
  
  .avatar-large {
    width: 80px;
    height: 80px;
  }
  
  .avatar-xl {
    width: 120px;
    height: 120px;
  }
}

/* ====================
   Double Tap Prevention
   ==================== */

.no-double-tap {
  touch-action: manipulation;
}

/* ====================
   Keyboard Optimization
   ==================== */

@media (max-height: 600px) {
  /* Hide header when keyboard is visible */
  .sticky-header {
    position: relative;
  }
}

/* ====================
   Thumb-Friendly Layout
   ==================== */

@media (max-width: 480px) {
  /* Move interactive elements to bottom for thumb reach */
  .actions-top {
    order: 2;
    margin-top: 16px;
  }
  
  .content {
    order: 1;
  }
  
  /* Wider buttons for thumb */
  .action-button {
    min-width: 60px;
    padding: 12px;
  }
}

/* ====================
   Mobile Menu Animation
   ==================== */

.sidebar {
  will-change: transform;
}

@media (max-width: 767px) {
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
}

/* ====================
   Mobile Haptic Feedback
   ==================== */

@supports (--webkit-touch-callout: none) {
  /* iOS specific improvements */
  button, a, input[type="button"] {
    -webkit-user-select: none;
    user-select: none;
  }
  
  /* Prevent zoom on double-tap */
  a, button {
    touch-action: manipulation;
  }
}

/* ====================
   Mobile Scrolling
   ==================== */

@media (max-width: 768px) {
  html {
    scroll-behavior: smooth;
  }
  
  /* Momentum scrolling */
  .scrollable {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Prevent scroll bounce on fixed elements */
  body.modal-open {
    overflow: hidden;
  }
}

/* ====================
   Mobile Performance
   ==================== */

@media (max-width: 640px) {
  /* Reduce animations on mobile */
  * {
    animation-duration: 0.2s;
  }
  
  /* Use transform for better performance */
  .mobile-nav {
    transform: translateZ(0);
    backface-visibility: hidden;
  }
}

/* ====================
   Input Usability
   ==================== */

@media (max-width: 640px) {
  /* Better spacing for inputs */
  .form-group {
    margin-bottom: 16px;
  }
  
  label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
  }
  
  /* Full-width inputs */
  input, textarea, select {
    width: 100%;
    max-width: 100%;
  }
  
  /* Better checkboxes */
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    cursor: pointer;
  }
}

/* ====================
   Safe Area Insets
   ==================== */

@supports (padding: max(0px)) {
  .safe-area {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  
  .safe-area-x {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  
  .safe-area-y {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}
