/* ========================================
   MOBILE SPECIFIC FIXES & ENHANCEMENTS
   Critical fixes for mobile devices
   ======================================== */

/* ========================================
   PREVENT HORIZONTAL SCROLL
   ======================================== */

* {
    box-sizing: border-box;
}

.row {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* ========================================
   MOBILE VIEWPORT FIXES
   ======================================== */

@media (max-width: 768px) {
    /* Fix for iOS Safari viewport */
    body {
        min-height: -webkit-fill-available;
        padding-top: 110px !important;
    }

    html {
        height: -webkit-fill-available;
    }

    /* Prevent text inflation on mobile */
    body {
        text-size-adjust: 100%;
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }

    /* Adjust carousel position for mobile header */
    .container-fluid.carousel {
        margin-top: 0 !important;
        top: -10px;
    }
}

@media (max-width: 576px) {
    body {
        padding-top: 110px !important;
    }

    .container-fluid.carousel {
        top: -8px;
    }
}

@media (max-width: 400px) {
    body {
        padding-top: 110px !important;
    }

    .container-fluid.carousel {
        top: -5px;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */

/* Remove tap highlight on mobile */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-tap-highlight-color: transparent;
}

/* Better touch scrolling */
.owl-carousel,
.header-carousel {
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   MOBILE SERVICES SECTION FIX
   ======================================== */

@media (max-width: 575px) {
    /* Ensure services fit properly on mobile */
    .container-fluid.px-0 .row {
        margin: 0 !important;
    }

    .container-fluid.px-0 .col-6 {
        padding: 0 !important;
    }

    /* Prevent icon/text overlap */
    .container-fluid.px-0 .col-6 .d-flex,
    .container-fluid.px-0 .col-6 .d-inline-flex {
        flex-wrap: nowrap !important;
        align-items: flex-start !important;
    }

    .container-fluid.px-0 .col-6 i {
        flex-shrink: 0;
    }
}

/* ========================================
   MOBILE IMAGE LOADING & FITTING
   ======================================== */

@media (max-width: 768px) {
    /* Optimize image loading on mobile */
    img {
        loading: lazy;
    }

    .header-carousel-item img {
        loading: eager; /* Carousel images should load immediately */
        object-fit: cover !important;
        object-position: center !important;
        width: 100% !important;
        height: 100% !important;
    }

    /* Ensure carousel items display properly */
    .header-carousel-item {
        display: block !important;
        background: transparent !important;
        overflow: hidden !important;
    }
}

@media (max-width: 576px) {
    .header-carousel-item img {
        object-fit: cover !important;
    }
}

@media (max-width: 400px) {
    .header-carousel-item img {
        object-fit: cover !important;
    }
}

/* ========================================
   MOBILE CAROUSEL TOUCH IMPROVEMENTS
   ======================================== */

@media (max-width: 768px) {
    .header-carousel {
        touch-action: pan-y;
    }

    .owl-stage-outer {
        overflow: hidden;
        -webkit-user-select: none;
        user-select: none;
    }

    /* Make navigation easier to tap */
    .header-carousel .owl-nav button,
    .header-carousel .owl-dot {
        touch-action: manipulation;
    }

    /* Better mobile carousel navigation */
    .header-carousel .owl-nav {
        left: 10px !important;
        right: 10px !important;
    }

    .header-carousel .owl-nav button {
        width: 35px !important;
        height: 35px !important;
        background: rgba(255, 255, 255, 0.3) !important;
        border: 1px solid rgba(255, 255, 255, 0.4) !important;
    }

    .header-carousel .owl-nav button span,
    .header-carousel .owl-nav button .nav-arrow {
        font-size: 18px !important;
    }

    /* Smaller dots for mobile */
    .header-carousel .owl-dots {
        bottom: 15px !important;
        right: 15px !important;
        gap: 8px !important;
    }

    .header-carousel .owl-dot {
        width: 32px !important;
        height: 32px !important;
        font-size: 11px !important;
        background: rgba(255, 255, 255, 0.4) !important;
        border: 1px solid rgba(255, 255, 255, 0.5) !important;
    }

    .header-carousel .owl-dot.active {
        background: rgba(255, 255, 255, 0.9) !important;
        border-color: rgba(255, 255, 255, 0.9) !important;
    }
}

@media (max-width: 576px) {
    .header-carousel .owl-nav button {
        width: 30px !important;
        height: 30px !important;
    }

    .header-carousel .owl-nav button span,
    .header-carousel .owl-nav button .nav-arrow {
        font-size: 16px !important;
    }

    .header-carousel .owl-dots {
        bottom: 12px !important;
        right: 12px !important;
        gap: 6px !important;
    }

    .header-carousel .owl-dot {
        width: 28px !important;
        height: 28px !important;
        font-size: 10px !important;
    }
}

@media (max-width: 400px) {
    .header-carousel .owl-nav button {
        width: 28px !important;
        height: 28px !important;
    }

    .header-carousel .owl-nav button span,
    .header-carousel .owl-nav button .nav-arrow {
        font-size: 14px !important;
    }

    .header-carousel .owl-dots {
        bottom: 10px !important;
        right: 10px !important;
        gap: 5px !important;
    }

    .header-carousel .owl-dot {
        width: 26px !important;
        height: 26px !important;
        font-size: 9px !important;
    }
}

/* ========================================
   MOBILE FONT ADJUSTMENTS
   ======================================== */

@media (max-width: 576px) {
    /* Ensure readable text on small screens */
    body {
        font-size: 14px;
        line-height: 1.5;
    }

    p {
        font-size: 14px;
        line-height: 1.6;
    }

    small {
        font-size: 12px;
    }
}

@media (max-width: 400px) {
    body {
        font-size: 13px;
    }

    p {
        font-size: 13px;
    }
}

/* ========================================
   MOBILE SPACING ADJUSTMENTS
   ======================================== */

@media (max-width: 576px) {
    /* Reduce spacing on mobile for better content fit */
    .py-5 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }

    .py-4 {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }

    .my-5 {
        margin-top: 2rem !important;
        margin-bottom: 2rem !important;
    }

    .my-4 {
        margin-top: 1.5rem !important;
        margin-bottom: 1.5rem !important;
    }
}

/* ========================================
   PREVENT CONTENT SHIFT
   ======================================== */

/* Prevent horizontal overscroll only */
@media (max-width: 768px) {
    body {
        overscroll-behavior-x: none;
    }
}

/* ========================================
   MOBILE BUTTON IMPROVEMENTS
   ======================================== */

@media (max-width: 576px) {
    .btn {
        padding: 10px 20px;
        font-size: 14px;
    }

    .btn-lg {
        padding: 12px 24px;
        font-size: 16px;
    }

    .btn-sm {
        padding: 8px 16px;
        font-size: 12px;
    }
}

/* ========================================
   MOBILE FORM ELEMENTS
   ======================================== */

@media (max-width: 576px) {
    input,
    textarea,
    select {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"] {
        -webkit-appearance: none;
        appearance: none;
    }
}

/* ========================================
   MOBILE GRID IMPROVEMENTS
   ======================================== */

@media (max-width: 575px) {
    /* Ensure 2-column grid for products on mobile */
    .col-lg-3.col-md-6.col-sm-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Add small gap between items */
    .g-4.row > * {
        padding-right: 0.4rem;
        padding-left: 0.4rem;
    }
}

/* ========================================
   MOBILE OVERFLOW FIXES
   ======================================== */

@media (max-width: 768px) {
    /* Prevent horizontal overflow from any element */
    .container-fluid,
    .row,
    .col-12,
    [class*="col-"] {
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Fix specific sections */
    .container-fluid.carousel,
    .container-fluid.px-0,
    .container-fluid.bg-light,
    .container-fluid.bg-white {
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* Ensure rows don't cause overflow */
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
    }

    /* Fix for wide tables or elements */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Ensure images don't cause overflow */
    img {
        max-width: 100%;
        height: auto;
    }
}

/* ========================================
   MOBILE NAVBAR IMPROVEMENTS
   ======================================== */

@media (max-width: 991px) {
    /* Ensure navbar doesn't cause horizontal scroll */
    .navbar {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .navbar-brand {
        margin-right: 0.5rem;
    }

    /* Better mobile menu */
    .navbar-collapse {
        max-height: calc(100vh - 100px);
        overflow-y: auto;
    }
}

/* ========================================
   MOBILE LINK & BUTTON TOUCH TARGETS
   ======================================== */

@media (max-width: 768px) {
    /* Ensure all clickable elements are easily tappable */
    a,
    button,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        padding: 8px 12px;
    }

    /* Social media icons */
    .fab,
    .fas {
        padding: 8px;
    }
}

/* ========================================
   MOBILE PERFORMANCE
   ======================================== */

@media (max-width: 768px) {
    /* Reduce animations on low-end devices */
    @media (prefers-reduced-motion: reduce),
           (update: slow) {
        * {
            animation-duration: 0.001ms !important;
            transition-duration: 0.001ms !important;
        }
    }

    /* Use simpler transforms on mobile */
    .explore-product-item:hover {
        transform: translateY(-3px); /* Smaller transform for mobile */
    }
}

/* ========================================
   MOBILE SHADOW ADJUSTMENTS
   ======================================== */

@media (max-width: 576px) {
    /* Lighter shadows on mobile for better performance */
    .shadow,
    .shadow-sm {
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
    }

    .explore-product-item {
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08) !important;
    }

    .explore-product-item:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12) !important;
    }
}

/* ========================================
   SPECIFIC DEVICE FIXES
   ======================================== */

/* iPhone X, XS, 11 Pro, 12 Mini, 13 Mini */
@media only screen
    and (device-width: 375px)
    and (device-height: 812px)
    and (-webkit-device-pixel-ratio: 3) {

    .header-carousel .owl-item,
    .header-carousel-item {
        height: 380px !important;
    }
}

/* iPhone XR, 11, 12, 13, 14 */
@media only screen
    and (device-width: 414px)
    and (device-height: 896px)
    and (-webkit-device-pixel-ratio: 2) {

    .header-carousel .owl-item,
    .header-carousel-item {
        height: 400px !important;
    }
}

/* iPhone 12 Pro Max, 13 Pro Max, 14 Plus */
@media only screen
    and (device-width: 428px)
    and (device-height: 926px)
    and (-webkit-device-pixel-ratio: 3) {

    .header-carousel .owl-item,
    .header-carousel-item {
        height: 420px !important;
    }
}

/* iPad Mini, Air */
@media only screen
    and (min-device-width: 768px)
    and (max-device-width: 1024px) {

    .header-carousel .owl-item,
    .header-carousel-item {
        height: 480px !important;
    }

    .explore-product-item {
        padding: 22px 15px !important;
    }
}

/* Galaxy Fold */
@media only screen
    and (device-width: 280px)
    and (device-height: 653px) {

    .container-fluid.bg-light h1 {
        font-size: 18px !important;
    }

    .explore-product-item h5 {
        font-size: 9px !important;
    }
}

/* ========================================
   MOBILE ORIENTATION LOCK HANDLING
   ======================================== */

@media (max-width: 768px) and (orientation: portrait) {
    .header-carousel .owl-item,
    .header-carousel-item {
        height: 400px !important;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .header-carousel .owl-item,
    .header-carousel-item {
        height: 70vh !important;
        max-height: 400px !important;
    }

    /* Reduce vertical padding in landscape */
    .container-fluid.bg-light,
    .container-fluid.bg-white {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
}

/* ========================================
   MOBILE ACCESSIBILITY
   ======================================== */

@media (max-width: 768px) {
    /* Larger focus indicators for mobile */
    *:focus {
        outline: 3px solid #667eea;
        outline-offset: 2px;
    }

    /* Skip to content link for screen readers */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 0;
        background: #667eea;
        color: white;
        padding: 8px;
        z-index: 100000;
    }

    .skip-to-content:focus {
        top: 0;
    }
}

/* ========================================
   MOBILE LOADING STATES
   ======================================== */

@media (max-width: 768px) {
    /* Optimize spinner for mobile */
    #spinner {
        backdrop-filter: blur(5px);
    }

    .spinner-border {
        width: 2.5rem !important;
        height: 2.5rem !important;
    }
}

/* ========================================
   MOBILE CONTENT VISIBILITY
   ======================================== */

/* Hide certain elements on very small screens if needed */
@media (max-width: 360px) {
    .d-none-mobile-sm {
        display: none !important;
    }
}

/* ========================================
   END OF MOBILE FIXES
   ======================================== */
