/* ========================================
   Mobile Fixes and Tweaks
   Specific fixes for common mobile issues
   ======================================== */

/* ========================================
   1. Header Fixes
   ======================================== */

/* Fix header overlap on mobile */
@media (max-width: 991px) {
  body {
    padding-top: 0 !important;
  }
  
  .th-header {
    position: sticky;
    top: 0;
    z-index: 999;
    transition: transform 0.3s ease;
  }
  
  .th-header.sticky-active {
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  }
}

/* ========================================
   2. Mobile Menu Improvements
   ======================================== */

@media (max-width: 991px) {
  /* Ensure menu appears above everything */
  .th-menu-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999 !important;
    background: rgba(0,0,0,0.6);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  
  .th-menu-wrapper.show,
  .th-menu-wrapper.th-body-visible {
    opacity: 1;
    visibility: visible;
  }
  
  .th-menu-area {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 85%;
    max-width: 350px;
    background: #fff;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    box-shadow: -5px 0 25px rgba(0,0,0,0.2);
  }
  
  .th-menu-wrapper.show .th-menu-area,
  .th-menu-wrapper.th-body-visible .th-menu-area {
    transform: translateX(0);
  }
  
  /* Mobile menu close button */
  .th-menu-area .th-menu-toggle,
  .th-menu-wrapper .th-menu-toggle {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 44px;
    height: 44px;
    background: rgba(13, 94, 244, 0.1);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--theme-color);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
  }
  
  .th-menu-area .th-menu-toggle:hover,
  .th-menu-wrapper .th-menu-toggle:hover {
    background: var(--theme-color);
    color: #fff;
    transform: rotate(90deg);
  }
}

/* ========================================
   3. Typography Adjustments
   ======================================== */

@media (max-width: 767px) {
  /* Ensure readable text on mobile */
  body {
    font-size: 15px;
    line-height: 1.6;
  }
  
  h1, .h1 {
    font-size: 28px !important;
    line-height: 1.3 !important;
  }
  
  h2, .h2 {
    font-size: 24px !important;
    line-height: 1.3 !important;
  }
  
  h3, .h3 {
    font-size: 20px !important;
    line-height: 1.4 !important;
  }
  
  h4, .h4 {
    font-size: 18px !important;
    line-height: 1.4 !important;
  }
  
  h5, .h5 {
    font-size: 16px !important;
    line-height: 1.4 !important;
  }
  
  h6, .h6 {
    font-size: 15px !important;
    line-height: 1.4 !important;
  }
  
  /* Prevent text overflow */
  p, li, td, th {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
}

/* ========================================
   4. Image Responsiveness
   ======================================== */

@media (max-width: 767px) {
  img {
    max-width: 100%;
    height: auto;
  }
  
  /* Prevent layout shift */
  img[width][height] {
    height: auto;
  }
  
  /* Lazy loading placeholder */
  img[data-src] {
    background: #f5f5f5;
    min-height: 200px;
  }
}

/* ========================================
   5. Container and Grid Fixes
   ======================================== */

@media (max-width: 767px) {
  .container {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }
  
  .row {
    margin-left: -10px !important;
    margin-right: -10px !important;
  }
  
  .row > * {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  
  /* Full width on mobile */
  .col-mobile-12 {
    width: 100% !important;
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }
}

/* ========================================
   6. Form Elements Mobile
   ======================================== */

@media (max-width: 767px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important; /* Prevent zoom on iOS */
    padding: 12px 15px !important;
        padding-right: 35px!important;
    border-radius: 8px;
  }
  .flex.items-center.gap-2.text-purple-700.font-bold {
    display: none !important;
  }
  .form-control {
    font-size: 16px !important;
  }
  
  /* Full width buttons on mobile */
  .btn-mobile-block {
    display: block;
    width: 100%;
    margin-bottom: 10px;
  }
  
  /* Larger touch targets for checkboxes and radios */
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    margin-left: 10px;
  }
}

/* ========================================
   7. Spacing Adjustments
   ======================================== */

@media (max-width: 767px) {
  /* Reduce excessive spacing on mobile */
  .mb-5, .my-5 {
    margin-bottom: 2rem !important;
  }
  
  .mt-5, .my-5 {
    margin-top: 2rem !important;
  }
  
  .pb-5, .py-5 {
    padding-bottom: 2rem !important;
  }
  
  .pt-5, .py-5 {
    padding-top: 2rem !important;
  }
  
  /* Compact sections on mobile */
  section.space {
    padding: 50px 0 !important;
  }
  
  .space-extra {
    padding: 40px 0 !important;
  }
}

/* ========================================
   8. Swiper/Slider Fixes
   ======================================== */

@media (max-width: 767px) {
  .swiper-container,
  .swiper {
    overflow: hidden;
    margin-left: -10px;
    margin-right: -10px;
    padding-left: 10px;
    padding-right: 10px;
  }
  
  .swiper-slide {
    height: auto;
  }
  
  /* Navigation arrows on mobile */
  .swiper-button-next,
  .swiper-button-prev {
    width: 35px !important;
    height: 35px !important;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  }
  
  .swiper-button-next:after,
  .swiper-button-prev:after {
    font-size: 16px !important;
    color: var(--theme-color);
  }
  
  /* Pagination bullets */
  .swiper-pagination-bullet {
    width: 8px !important;
    height: 8px !important;
  }
  
  .swiper-pagination-bullet-active {
    width: 20px !important;
    border-radius: 4px !important;
  }
}

/* ========================================
   9. Modal and Popup Fixes
   ======================================== */

@media (max-width: 767px) {
  .modal-dialog {
    margin: 10px !important;
    max-width: calc(100% - 20px) !important;
  }
  
  .modal-content {
    border-radius: 12px !important;
  }
  
  .modal-header,
  .modal-footer {
    padding: 15px !important;
  }
  
  .modal-body {
    padding: 20px 15px !important;
  }
  
  /* Popup search */
  .popup-search-box {
    padding: 20px !important;
  }
  
  .popup-search-box input {
    font-size: 16px !important;
  }
}

/* ========================================
   10. Table Responsiveness
   ======================================== */

@media (max-width: 767px) {
  .table-responsive {
    border: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    font-size: 14px !important;
  }
  
  table th,
  table td {
    padding: 10px 8px !important;
    white-space: nowrap;
  }
}

/* ========================================
   11. Breadcrumb Mobile
   ======================================== */

@media (max-width: 767px) {
  .breadcumb-wrapper {
    padding: 60px 0 !important;
  }
  
  .breadcumb-title {
    font-size: 24px !important;
    margin-bottom: 15px !important;
  }
  
  .breadcumb-menu {
    font-size: 13px !important;
  }
  
  .breadcumb-menu li {
    display: inline-block;
  }
  
  .breadcumb-menu li:not(:last-child):after {
    content: '/';
    margin: 0 8px;
    opacity: 0.5;
  }
}

/* ========================================
   12. Fix Overlapping Elements
   ======================================== */

@media (max-width: 767px) {
  /* Prevent z-index issues */
  .sticky-active {
    z-index: 999 !important;
  }
  
  /* Fix dropdown menus */
  .dropdown-menu {
    font-size: 14px;
    min-width: 200px;
  }
  
  /* Fix tooltips */
  .tooltip {
    font-size: 12px;
  }
}

/* ========================================
   13. Performance Optimizations
   ======================================== */

@media (max-width: 767px) {
  /* Disable hover effects on touch devices */
  @media (hover: none) {
    .hover-effect:hover {
      transform: none !important;
    }
    
    a:hover,
    button:hover {
      opacity: 1 !important;
    }
  }
  
  /* Reduce motion for better performance */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* ========================================
   14. iOS Specific Fixes
   ======================================== */

@supports (-webkit-touch-callout: none) {
  /* iOS Safari specific fixes */
  @media (max-width: 767px) {
    /* Fix 100vh issue on iOS */
    .full-height-mobile {
      min-height: calc(var(--vh, 1vh) * 100);
    }
    
    /* Fix sticky positioning */
    .sticky-header {
      position: -webkit-sticky;
      position: sticky;
    }
    
    /* Prevent iOS bounce scroll */
    body {
      position: relative;
      overflow-x: hidden;
    }
  }
}

/* ========================================
   15. Android Specific Fixes
   ======================================== */

@media (max-width: 767px) {
  /* Chrome on Android specific */
  input,
  textarea,
  select {
    /* Prevent zoom on focus */
    font-size: 16px !important;
  }
  
  /* Fix viewport units */
  .android-fix {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }
}

/* ========================================
   16. Accessibility Improvements
   ======================================== */

@media (max-width: 767px) {
  
  /* Skip to content link */
  .skip-to-content {
    position: absolute;
    top: -100px;
    left: 20px;
    background: var(--theme-color);
    color: #fff;
    padding: 12px 20px;
    border-radius: 5px;
    z-index: 10000;
  }
  
  .skip-to-content:focus {
    top: 20px;
  }
}

/* ========================================
   17. Print Styles
   ======================================== */

@media print {
  .th-header,
  .th-footer,
  .mobile-auth-buttons,
  .header-button,
  .th-menu-toggle {
    display: none !important;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.5;
  }
  
  a {
    text-decoration: underline;
  }
}

/* ========================================
   18. Dark Mode Support (Optional)
   ======================================== */

@media (prefers-color-scheme: dark) {
  @media (max-width: 767px) {
    /* Add dark mode styles if needed */
    /* body {
      background-color: #1a1a1a;
      color: #f5f5f5;
    } */
  }
}

/* ========================================
   19. Loading States
   ======================================== */

@media (max-width: 767px) {
  .loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 8px;
  }
  
  @keyframes loading {
    0% {
      background-position: 200% 0;
    }
    100% {
      background-position: -200% 0;
    }
  }
}

/* ========================================
   20. Safe Area Insets (for notched devices)
   ======================================== */

@media (max-width: 767px) {
  @supports (padding: max(0px)) {
    .safe-area-top {
      padding-top: max(20px, env(safe-area-inset-top));
    }
    
    .safe-area-bottom {
      padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    .safe-area-left {
      padding-left: max(15px, env(safe-area-inset-left));
    }
    
    .safe-area-right {
      padding-right: max(15px, env(safe-area-inset-right));
    }
  }
}
