/**
 * Wazobia List - Listing Detail Mobile Enhancements
 * Version: 2.0
 * Focus: Mobile-first UI/UX improvements
 */

/* ============================================
   1. MOBILE IMAGE GALLERY WITH SWIPE SUPPORT
   ============================================ */

@media (max-width: 767px) {
  /* Make carousel swipeable and touch-friendly */
  #listingCarousel .carousel-inner {
    touch-action: pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    overflow: hidden;
  }
  
  /* Hide carousel arrow controls on mobile - rely on swipe */
  #listingCarousel .carousel-control-prev,
  #listingCarousel .carousel-control-next {
    display: none;
  }
  
  /* Show page indicators for better navigation feedback */
  #listingCarousel .carousel-indicators {
    display: flex !important;
    bottom: 12px;
    margin-bottom: 0;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  [data-bs-theme="dark"] #listingCarousel .carousel-indicators {
    background: rgba(0, 0, 0, 0.35);
  }
  
  #listingCarousel .carousel-indicators button {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.25);
    margin: 0;
    opacity: 1;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    transition: all 0.3s ease;
  }
  
  #listingCarousel .carousel-indicators button.active {
    background-color: #fff;
    width: 24px;
    border-radius: 4px;
    border-color: rgba(0, 0, 0, 0.35);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }
  
  /* Hide thumbnails on mobile to save space */
  [data-carousel-thumb],
  #listingCarouselLive {
    display: none !important;
  }
  
  /* Add subtle shadow for depth */
  #listingCarousel {
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    margin-bottom: 16px;
  }
  
  [data-bs-theme="dark"] #listingCarousel {
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  }
}

/* ============================================
   2. STICKY CTA BAR FOR MOBILE
   ============================================ */

@media (max-width: 767px) {
  .mobile-sticky-cta {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 12px 16px;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.1);
    z-index: 1000;
    display: flex;
    gap: 10px;
    align-items: center;
    animation: slideUpIn 0.3s ease-out;
  }
  
  @keyframes slideUpIn {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }
  
  [data-bs-theme="dark"] .mobile-sticky-cta {
    background: rgba(22, 27, 34, 0.98);
    border-top: 1px solid var(--dark-card-border);
  }
  
  .mobile-sticky-cta .btn-primary {
    flex: 1;
    font-weight: 600;
    padding: 14px 20px;
    font-size: 16px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
  }
  
  .mobile-sticky-cta .btn-primary:active {
    transform: scale(0.98);
  }
  
  .mobile-sticky-cta .btn-favorite {
    width: 52px;
    height: 52px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 2px solid #dee2e6;
    background: #fff;
    transition: all 0.2s;
  }
  
  [data-bs-theme="dark"] .mobile-sticky-cta .btn-favorite {
    background: var(--dark-card-bg);
    border-color: var(--dark-card-border);
  }
  
  .mobile-sticky-cta .btn-favorite:active {
    transform: scale(0.95);
  }
  
  /* Add bottom padding to content so it doesn't hide behind sticky bar */
  .container {
    padding-bottom: 90px !important;
  }
}

/* ============================================
   3. ENHANCED PRICE PROMINENCE
   ============================================ */

@media (max-width: 767px) {
  .listing-price-container {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 16px;
    border-radius: 12px;
    margin: 16px 0;
    border: 2px solid #198754;
    box-shadow: 0 2px 8px rgba(25, 135, 84, 0.15);
  }
  
  [data-bs-theme="dark"] .listing-price-container {
    background: linear-gradient(135deg, #1a1f25 0%, #21262d 100%);
    border-color: #238636;
    box-shadow: 0 2px 8px rgba(35, 134, 54, 0.2);
  }
  
  .listing-price-label {
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 700;
    color: #6c757d;
    letter-spacing: 0.8px;
    margin-bottom: 4px;
  }
  
  [data-bs-theme="dark"] .listing-price-label {
    color: #9b9b9b;
  }
  
  .listing-price {
    font-size: 34px !important;
    font-weight: 800 !important;
    color: #198754 !important;
    letter-spacing: -0.5px;
    margin: 0 !important;
    line-height: 1.1;
  }
  
  [data-bs-theme="dark"] .listing-price {
    color: #7ee787 !important;
  }
  
  .listing-condition-badge {
    margin-top: 10px;
    display: inline-block;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 600;
  }
}

/* ============================================
   4. COMPACT MOBILE SELLER CARD
   ============================================ */

@media (max-width: 767px) {
  /* Hide desktop seller card on mobile */
  .seller-card-desktop {
    display: none !important;
  }
  
  .seller-card-mobile {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 14px;
    margin: 16px 0;
    border: 1px solid #dee2e6;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }
  
  [data-bs-theme="dark"] .seller-card-mobile {
    background: var(--dark-card-bg);
    border-color: var(--dark-card-border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }
  
  .seller-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
  }
  
  .seller-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 22px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  }
  
  .seller-info-compact {
    flex: 1;
    min-width: 0;
  }
  
  .seller-name {
    font-weight: 700;
    font-size: 16px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.3;
  }
  
  .seller-location {
    font-size: 13px;
    color: #6c757d;
    margin: 3px 0 0 0;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  
  [data-bs-theme="dark"] .seller-location {
    color: #9b9b9b;
  }
  
  .seller-rating-compact {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    margin-top: 4px;
    font-weight: 600;
  }
  
  .seller-rating-compact .text-warning {
    font-size: 14px;
  }
  
  .seller-verification-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #d1e7dd;
    color: #0f5132;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 700;
    margin-top: 10px;
  }
  
  [data-bs-theme="dark"] .seller-verification-badge {
    background: rgba(63, 185, 80, 0.15);
    color: #7ee787;
  }
  
  .seller-quick-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
  }
  
  .seller-quick-actions .btn {
    flex: 1;
    font-size: 13px;
    padding: 10px 14px;
    border-radius: 8px;
    font-weight: 600;
    min-height: 40px;
  }
}

/* ============================================
   5. COLLAPSIBLE SAFETY TIPS
   ============================================ */

@media (max-width: 767px) {
  /* Hide desktop safety tips */
  .safety-tips-desktop {
    display: none !important;
  }
  
  .safety-tips-mobile {
    background: #fff3cd;
    border-radius: 10px;
    padding: 12px;
    margin: 16px 0;
    border: 1px solid #ffc107;
    box-shadow: 0 1px 3px rgba(255, 193, 7, 0.2);
  }
  
  [data-bs-theme="dark"] .safety-tips-mobile {
    background: rgba(255, 193, 7, 0.1);
    border-color: rgba(255, 193, 7, 0.3);
  }
  
  .safety-tips-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  
  .safety-tips-header h6 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: #856404;
    flex: 1;
  }
  
  [data-bs-theme="dark"] .safety-tips-header h6 {
    color: #f7dc6f;
  }
  
  .safety-tips-toggle {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
    font-size: 12px;
  }
  
  [data-bs-theme="dark"] .safety-tips-toggle {
    background: rgba(255,255,255,0.1);
  }
  
  .safety-tips-toggle.expanded {
    transform: rotate(180deg);
    background: rgba(0,0,0,0.12);
  }
  
  .safety-tips-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }
  
  .safety-tips-content.show {
    max-height: 600px;
    margin-top: 12px;
  }
  
  .safety-tips-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 13px;
  }
  
  .safety-tips-content li {
    padding: 8px 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    line-height: 1.5;
  }
  
  .safety-tips-content li i {
    flex-shrink: 0;
    margin-top: 2px;
    font-size: 14px;
  }
}

/* ============================================
   6. IMPROVED MOBILE TYPOGRAPHY & SPACING
   ============================================ */

@media (max-width: 767px) {
  /* Title - make it bigger and bolder */
  h1[data-testid="listing-title"] {
    font-size: 26px !important;
    font-weight: 800 !important;
    line-height: 1.25 !important;
    margin-bottom: 10px !important;
    letter-spacing: -0.4px;
    color: #212529;
  }
  
  [data-bs-theme="dark"] h1[data-testid="listing-title"] {
    color: #e6edf3;
  }
  
  /* Meta info - smaller and less prominent */
  .text-muted.small {
    font-size: 12px !important;
    line-height: 1.6;
  }
  
  /* Section headers */
  .card-header h5 {
    font-size: 16px !important;
    font-weight: 700 !important;
    margin: 0;
  }
  
  /* Body text */
  .card-body {
    font-size: 15px;
    line-height: 1.6;
  }
  
  /* Key details - better readability */
  .card-body dl.row {
    font-size: 14px;
  }
  
  .card-body dl.row dt {
    font-size: 13px !important;
    font-weight: 600 !important;
    color: #6c757d;
  }
  
  [data-bs-theme="dark"] .card-body dl.row dt {
    color: #9b9b9b;
  }
  
  .card-body dl.row dd {
    font-size: 14px !important;
    font-weight: 500;
  }
  
  /* Improve spacing between sections */
  .card + .card {
    margin-top: 12px !important;
  }
  
  /* Reduce card padding on mobile */
  .card-body {
    padding: 14px !important;
  }
  
  .card-header {
    padding: 12px 14px !important;
    border-bottom: 1px solid #e9ecef;
  }
  
  [data-bs-theme="dark"] .card-header {
    border-bottom-color: var(--dark-card-border);
  }
  
  /* Better button sizing for touch */
  .btn {
    min-height: 44px;
    font-weight: 600;
    border-radius: 10px;
  }
  
  .btn-sm {
    min-height: 38px;
    font-size: 14px;
    border-radius: 8px;
  }
  
  /* Card design improvements */
  .card {
    border-radius: 12px;
    border: 1px solid #e9ecef;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }
  
  [data-bs-theme="dark"] .card {
    border-color: var(--dark-card-border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }
}

/* ============================================
   7. OPTIMIZED BREADCRUMBS FOR MOBILE
   ============================================ */

@media (max-width: 767px) {
  nav[aria-label="Breadcrumb"] {
    margin-bottom: 12px !important;
  }
  
  .breadcrumb {
    font-size: 11px;
    padding: 6px 0;
    margin-bottom: 0 !important;
    background: transparent;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
  }
  
  .breadcrumb::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }
  
  .breadcrumb-item {
    display: inline-block;
  }
  
  .breadcrumb-item a {
    color: #6c757d;
    text-decoration: none;
  }
  
  [data-bs-theme="dark"] .breadcrumb-item a {
    color: #9b9b9b;
  }
  
  .breadcrumb-item.active {
    color: #495057;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: bottom;
  }
  
  [data-bs-theme="dark"] .breadcrumb-item.active {
    color: #e6edf3;
  }
}

/* ============================================
   8. IMPROVED ACTION BUTTONS LAYOUT
   ============================================ */

@media (max-width: 767px) {
  .listing-actions-mobile {
    display: flex;
    gap: 8px;
    margin: 16px 0;
  }
  
  .listing-actions-mobile .btn {
    min-height: 44px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
  }
  
  .listing-actions-mobile .btn-share {
    flex: 1;
  }
  
  .listing-actions-mobile .btn-report {
    min-width: 44px;
    padding: 0 16px;
  }
}

/* ============================================
   9. PERFORMANCE & LOADING STATES
   ============================================ */

@media (max-width: 767px) {
  /* Skeleton loading for images */
  .carousel-item .ratio {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
  }
  
  [data-bs-theme="dark"] .carousel-item .ratio {
    background: linear-gradient(90deg, #1a1f25 25%, #21262d 50%, #1a1f25 75%);
    background-size: 200% 100%;
  }
  
  @keyframes shimmer {
    0% {
      background-position: 200% 0;
    }
    100% {
      background-position: -200% 0;
    }
  }
  
  .carousel-item img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
  }
  
  .carousel-item img[loading="lazy"].loaded {
    opacity: 1;
  }
}

/* ============================================
   10. SUBTLE SCROLL ANIMATIONS
   ============================================ */

@media (max-width: 767px) {
  .listing-content-animate {
    animation: fadeInUp 0.5s ease-out;
  }
  
  @keyframes fadeInUp {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  /* Stagger animation for cards */
  .card:nth-child(1) { 
    animation: fadeInUp 0.4s ease-out 0.1s both; 
  }
  .card:nth-child(2) { 
    animation: fadeInUp 0.4s ease-out 0.15s both; 
  }
  .card:nth-child(3) { 
    animation: fadeInUp 0.4s ease-out 0.2s both; 
  }
  .card:nth-child(4) { 
    animation: fadeInUp 0.4s ease-out 0.25s both; 
  }
}

/* ============================================
   11. DARK MODE SPECIFIC ENHANCEMENTS
   ============================================ */

[data-bs-theme="dark"] {
  /* Ensure cards have proper contrast */
  .card {
    background-color: var(--dark-card-bg) !important;
  }
  
  .card-header {
    background-color: var(--dark-hover-bg) !important;
  }
  
  /* Better text colors */
  .card-body {
    color: var(--bs-body-color);
  }
  
  /* Enhance button visibility */
  .btn-outline-primary {
    border-width: 2px;
  }
}

/* ============================================
   12. ACCESSIBILITY IMPROVEMENTS
   ============================================ */

@media (max-width: 767px) {
  /* Better focus states for keyboard navigation */
  .btn:focus-visible,
  a:focus-visible {
    outline: 3px solid #0d6efd;
    outline-offset: 2px;
    border-radius: 4px;
  }
  
  [data-bs-theme="dark"] .btn:focus-visible,
  [data-bs-theme="dark"] a:focus-visible {
    outline-color: #58a6ff;
  }
  
  /* Improve tap highlight */
  * {
    -webkit-tap-highlight-color: rgba(13, 110, 253, 0.1);
  }
  
  [data-bs-theme="dark"] * {
    -webkit-tap-highlight-color: rgba(88, 166, 255, 0.1);
  }
}

/* ============================================
   13. RESPONSIVE UTILITIES
   ============================================ */

@media (max-width: 767px) {
  /* Hide desktop-only elements */
  .d-mobile-none {
    display: none !important;
  }
  
  /* Utility classes */
  .mobile-mt-3 {
    margin-top: 1rem !important;
  }
  
  .mobile-mb-3 {
    margin-bottom: 1rem !important;
  }
  
  .mobile-p-2 {
    padding: 0.5rem !important;
  }
}
