/**
 * Mobile Enhancements CSS
 * =======================
 * 
 * Mobile-specific styles for:
 * - iOS-specific optimizations
 * - Touch-friendly interactions
 * - Mobile table card views
 * - Smooth transitions
 * - Fullscreen mobile experience
 */

/* iOS Specific Styles */
.ios-device {
  /* Prevent iOS bounce scroll */
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.ios-device body {
  position: fixed;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Safe Area Insets for iOS */
@supports (padding: max(0px)) {
  .ios-installed {
    padding-top: max(0px, env(safe-area-inset-top));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  .ios-installed .navbar {
    padding-top: max(1rem, calc(1rem + env(safe-area-inset-top)));
  }
  
  .ios-installed .bottom-nav-mobile {
    padding-bottom: max(1rem, calc(1rem + env(safe-area-inset-bottom)));
  }
}

/* Touch-Friendly Targets */
@media (max-width: 768px) {
  /* Minimum touch target size (44x44px) */
  button,
  a.btn,
  .btn,
  input[type="submit"],
  input[type="button"],
  .clickable {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  /* Touch feedback */
  button:active,
  a.btn:active,
  .btn:active {
    opacity: 0.7;
    transform: scale(0.98);
  }
  
  /* Prevent text selection on tap */
  button,
  a,
  .btn {
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    -webkit-touch-callout: none;
    user-select: none;
  }
  
  /* Allow text selection in inputs */
  input,
  textarea,
  [contenteditable] {
    user-select: text;
    -webkit-user-select: text;
  }
}

/* Mobile Table Card Views */
.mobile-table-cards {
  display: none;
}

@media (max-width: 768px) {
  .mobile-table-cards {
    display: block;
  }
  
  table[data-mobile-cards-created] {
    display: none;
  }
  
  .mobile-table-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
  }
  
  .mobile-table-card:active {
    transform: scale(0.98);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  }
  
  .mobile-table-card-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #f3f4f6;
  }
  
  .mobile-table-card-item:last-child {
    border-bottom: none;
  }
  
  .mobile-table-card-label {
    font-weight: 600;
    color: #6b7280;
    font-size: 0.9rem;
    flex-shrink: 0;
  }
  
  .mobile-table-card-value {
    color: #2d3748;
    font-size: 0.95rem;
    text-align: right;
    flex: 1;
    margin-left: 12px;
    word-break: break-word;
  }
}

/* Mobile Skeleton Loaders */
@media (max-width: 768px) {
  .mobile-skeleton {
    border-radius: 8px;
  }
  
  .skeleton-product-card {
    height: 350px;
  }
  
  .skeleton-table-row {
    height: 60px;
  }
  
  .skeleton-list-item {
    padding: 12px;
  }
}

/* Smooth Page Transitions */
@media (max-width: 768px) {
  body {
    transition: opacity 0.2s ease;
  }
  
  body.page-transitioning {
    opacity: 0.7;
  }
  
  /* Smooth scroll */
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
}

/* Fullscreen Mobile Experience */
@media (max-width: 768px) {
  /* Hide browser UI elements when in standalone */
  body.pwa-installed {
    /* Keep fixed nav spacing in standalone mode */
    margin: 0;
    padding-top: calc(var(--mobile-nav-height) + env(safe-area-inset-top));
    padding-bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
  
  body.pwa-installed .container,
  body.pwa-installed .container-fluid {
    padding-left: env(safe-area-inset-left, 15px);
    padding-right: env(safe-area-inset-right, 15px);
  }
}

/* Mobile-Optimized Forms */
@media (max-width: 768px) {
  /* All form inputs - prevent iOS 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"],
  input[type="datetime-local"],
  .form-control,
  .form-select,
  textarea,
  select {
    font-size: 16px !important; /* Prevents zoom on iOS */
    min-height: 44px;
    padding: 12px 16px;
    -webkit-appearance: none;
    border-radius: 8px;
  }
  
  /* Checkout-specific optimizations */
  .checkout-input {
    font-size: 16px !important;
    min-height: 44px;
    padding: 12px 16px;
  }
  
  .phone-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  
  .country-code-select {
    width: 100%;
    font-size: 16px !important;
  }
  
  .form-label {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
  }
  
  .form-group {
    margin-bottom: 1.5rem;
  }
  
  /* Stack form elements on mobile */
  .form-row {
    flex-direction: column;
  }
  
  .form-row .col,
  .form-row [class*="col-"] {
    width: 100%;
    margin-bottom: 1rem;
  }
}

/* Mobile-Optimized Cards */
@media (max-width: 768px) {
  .card {
    border-radius: 12px;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }
  
  .card-body {
    padding: 1rem;
  }
  
  .card-header {
    padding: 1rem;
    font-size: 1.1rem;
  }
  
  /* Remove hover effects on mobile */
  .card:hover {
    transform: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  }
}

/* Mobile-Optimized Buttons */
@media (max-width: 768px) {
  .btn {
    border-radius: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
  }
  
  .btn-group {
    flex-direction: column;
    width: 100%;
  }
  
  .btn-group .btn {
    width: 100%;
    margin-bottom: 8px;
  }
  
  /* Full-width buttons on mobile */
  .btn-mobile-full {
    width: 100%;
    margin-bottom: 12px;
  }
}

/* Mobile-Optimized Navigation */
@media (max-width: 768px) {
  .navbar {
    padding: 12px 16px;
  }
  
  .navbar-brand {
    font-size: 1.3rem;
  }
  
  .nav-link {
    padding: 12px 16px;
    font-size: 1rem;
  }
  
  /* Bottom navigation */
  .bottom-nav-mobile {
    padding: 12px 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  
  .bottom-nav-mobile-item {
    min-height: 44px;
    padding: 8px 12px;
  }
}

/* Mobile-Optimized Tables */
@media (max-width: 768px) {
  .table-responsive {
    border-radius: 12px;
    overflow: hidden;
  }
  
  .table {
    font-size: 0.9rem;
  }
  
  .table th,
  .table td {
    padding: 12px 8px;
    vertical-align: middle;
  }
  
  .table th {
    font-size: 0.85rem;
    font-weight: 600;
  }
  
  /* Hide less important columns on mobile */
  .table th.mobile-hide,
  .table td.mobile-hide {
    display: none;
  }
}

/* Mobile-Optimized Modals */
@media (max-width: 768px) {
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100%;
  }
  
  .modal-content {
    border-radius: 20px 20px 0 0;
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  
  .modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Mobile-Optimized Product Cards */
@media (max-width: 768px) {
  .product-card {
    margin-bottom: 16px;
  }
  
  .product-image-wrapper {
    height: 200px;
  }
  
  .product-info {
    padding: 12px;
  }
  
  .product-name {
    font-size: 0.95rem;
    line-height: 1.4;
  }
  
  .product-price {
    font-size: 1.2rem;
  }
  
  .btn-add-cart {
    width: 100%;
    margin-top: 8px;
  }
}

/* Mobile-Optimized Dashboards */
@media (max-width: 768px) {
  .dashboard-card {
    margin-bottom: 16px;
  }
  
  .dashboard-stat {
    font-size: 1.8rem;
  }
  
  .dashboard-label {
    font-size: 0.9rem;
  }
  
  /* Stack dashboard cards */
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

/* Mobile Loading States */
@media (max-width: 768px) {
  .loading-spinner {
    width: 32px;
    height: 32px;
  }
  
  .skeleton-loader {
    border-radius: 8px;
  }
}

/* Mobile-Specific Animations */
@media (max-width: 768px) {
  /* Reduce animation complexity */
  * {
    animation-duration: 0.3s !important;
    transition-duration: 0.3s !important;
  }
  
  /* Disable heavy animations */
  .card:hover {
    transform: none !important;
  }
  
  /* Simplify transitions */
  .fade-in {
    animation: fadeInMobile 0.3s ease;
  }
  
  @keyframes fadeInMobile {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}

/* iOS-Specific Fixes */
.ios-device {
  /* Fix iOS input zoom */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  textarea,
  select {
    font-size: 16px !important;
  }
  
  /* Fix iOS button highlight */
  button,
  a {
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
  }
  
  /* Fix iOS scroll bounce */
  body {
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: touch;
  }
}

/* Mobile Offline Indicator */
@media (max-width: 768px) {
  #offline-indicator {
    font-size: 0.9rem;
    padding: 10px;
  }
}

/* Mobile Update Prompt */
@media (max-width: 768px) {
  #pwa-update-prompt {
    left: 10px;
    right: 10px;
    max-width: 100%;
  }
  
  #pwa-update-prompt .bottom-sheet-content {
    border-radius: 20px 20px 0 0;
  }
}

/* Mobile Performance Optimizations */
@media (max-width: 768px) {
  /* Reduce repaints */
  .card,
  .btn,
  .nav-link {
    will-change: auto;
  }
  
  /* Optimize images */
  img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
  
  /* Reduce shadow complexity */
  .shadow,
  .shadow-sm,
  .shadow-lg {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
  }
}
