/**
 * iOS-Native Navigation System for Work Orders Manager
 * Bottom Tab Bar & Floating Action Button (FAB)
 * October 2025
 */

/* === MOBILE ADJUSTMENTS === */
@media (max-width: 767px) {
  /* Hide desktop navbar on mobile */
  .sfm-navbar {
    display: none !important;
  }

  /* Reset any header padding since we removed mobile header */
  main {
    padding-top: 0 !important;
  }

  /* Ensure no extra space at top */
  body::before {
    display: none;
  }

  /* Mobile Page Header with Hamburger Menu */
  .mobile-page-header {
    padding: 0.75rem 1rem;
    background: white;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    position: sticky;
    top: 0;
    z-index: 100;
    margin-bottom: 1rem;
  }

  .mobile-page-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: #212529;
  }

  .mobile-page-header .btn-link {
    color: #007AFF;
    text-decoration: none;
  }

  /* Mobile Menu Items */
  .mobile-menu-items {
    padding: 0.5rem 0;
    background: white;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  .mobile-menu-item {
    display: block;
    padding: 0.75rem 1rem;
    color: #212529;
    text-decoration: none;
    border-radius: 8px;
    margin: 0.25rem 0.5rem;
    transition: background 0.2s ease;
  }

  .mobile-menu-item:active {
    background: rgba(0, 122, 255, 0.1);
  }

  .mobile-menu-item.text-danger {
    color: #dc3545 !important;
  }

  /* Hide desktop "Create New Work Order" button on mobile */
  .btn-primary[href*="work_order_create"] {
    display: none;
  }
}

/* === BOTTOM TAB BAR (iOS Pattern) === */
@media (max-width: 767px) {

  /* Bottom Tab Bar Container */
  .ios-tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 49px; /* iOS standard tab bar height */
    background: rgba(248, 248, 248, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 0.5px solid rgba(0, 0, 0, 0.12);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1040;
    padding: 0 env(safe-area-inset-left) env(safe-area-inset-bottom) env(safe-area-inset-right);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Tab Items */
  .ios-tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4px 0;
    text-decoration: none;
    color: #8E8E93;
    transition: all 0.2s ease;
    position: relative;
    min-width: 48px;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
  }

  /* Tab Icons */
  .ios-tab-item i {
    font-size: 24px;
    margin-bottom: 2px;
    transition: transform 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  }

  /* Tab Labels */
  .ios-tab-item span {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: -0.02em;
  }

  /* Active Tab */
  .ios-tab-item.active {
    color: #007AFF;
  }

  .ios-tab-item.active i {
    transform: scale(1.1);
  }

  /* Tab Press Effect */
  .ios-tab-item:active {
    transform: scale(0.92);
  }

  /* Special styling for Create tab */
  .ios-tab-item--create {
    background: linear-gradient(135deg, #007AFF 0%, #0056CC 100%);
    color: white !important;
    border-radius: 8px;
    margin: 0 4px;
    padding: 6px 0;
  }

  .ios-tab-item--create:active {
    background: linear-gradient(135deg, #0056CC 0%, #003D99 100%);
    transform: scale(0.95);
  }

  .ios-tab-item--create i {
    font-size: 26px; /* Slightly larger icon for create */
  }

  /* Badge for notifications */
  .ios-tab-badge {
    position: absolute;
    top: 2px;
    right: calc(50% - 20px);
    background: #FF3B30;
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  /* Adjust main content for bottom tab bar */
  main {
    padding-bottom: calc(49px + env(safe-area-inset-bottom)) !important;
  }

  /* Dark mode support */
  @media (prefers-color-scheme: dark) {
    .ios-tab-bar {
      background: rgba(28, 28, 30, 0.95);
      border-top-color: rgba(255, 255, 255, 0.15);
    }

    .ios-tab-item {
      color: #8E8E93;
    }

    .ios-tab-item.active {
      color: #0A84FF;
    }
  }
}


/* === PULL-TO-REFRESH INDICATOR === */
.ios-pull-to-refresh {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ios-pull-to-refresh.visible {
  opacity: 1;
}

.ios-pull-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid #C7C7CC;
  border-top-color: #007AFF;
  border-radius: 50%;
  animation: ios-spin 0.8s linear infinite;
}

@keyframes ios-spin {
  to { transform: rotate(360deg); }
}

/* === SWIPE HINT INDICATORS === */
.ios-swipe-hint {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  color: #C7C7CC;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.work-order-item:hover .ios-swipe-hint {
  opacity: 1;
}

/* === STATUS BAR SAFE AREA === */
@media (max-width: 767px) {
  .ios-status-bar-spacer {
    height: env(safe-area-inset-top);
    background: rgba(248, 248, 248, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1041;
  }

  /* Adjust content for status bar */
  .container-fluid {
    padding-top: calc(16px + env(safe-area-inset-top)) !important;
  }
}

/* === HAPTIC FEEDBACK CLASSES === */
.ios-haptic-light {
  /* JavaScript will trigger haptic */
}

.ios-haptic-medium {
  /* JavaScript will trigger haptic */
}

.ios-haptic-heavy {
  /* JavaScript will trigger haptic */
}

/* === TRANSITIONS & ANIMATIONS === */
@media (prefers-reduced-motion: reduce) {
  .ios-tab-bar,
  .ios-tab-item,
  .ios-fab,
  .ios-fab-actions,
  .ios-fab-action {
    transition: none !important;
    animation: none !important;
  }
}