/**
 * XPEL Korea Mobile UX Fixes
 * Version 1.2
 * 
 * Fixes for:
 * - WordPress FSE double scroll (CRITICAL)
 * - Hero content clipping on mobile
 * - Header logo visibility
 * - Viewport overflow prevention
 * - Touch-friendly improvements
 */

/* ==========================================================================
   CRITICAL: WordPress FSE Double Scroll Fix
   
   WordPress FSE/block themes can create nested scrolling when:
   1. html/body have height: 100% or 100vh
   2. .wp-site-blocks has overflow: auto with min-height: 100vh
   
   This fix ensures only the html/body scrolls, not inner wrappers.
   ========================================================================== */

/* Reset any height constraints on html/body */
html {
    height: auto !important;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: scroll; /* Always show scrollbar to prevent layout shift */
}

body {
    height: auto !important;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: visible !important; /* Let html handle scrolling */
    position: relative;
    width: 100%;
}

/* WordPress FSE Block Wrappers - Remove all scroll behavior */
.wp-site-blocks {
    overflow: visible !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
}

body > .wp-site-blocks {
    overflow: visible !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    display: block !important;
}

/* WordPress layout classes */
.is-layout-flow,
.is-layout-constrained,
.is-layout-flex,
.has-global-padding {
    overflow: visible !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
}

/* WordPress root padding aware alignments wrapper */
.has-global-padding > .alignfull {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Ensure main content doesn't create scroll context */
main,
.site-main,
.entry-content,
.page-content,
.contact-page {
    overflow: visible !important;
    height: auto !important;
    min-height: auto !important;
}

/* WordPress admin bar adjustment for scroll */
body.admin-bar {
    margin-top: 0 !important;
    padding-top: 32px !important;
}

@media screen and (max-width: 782px) {
    body.admin-bar {
        padding-top: 46px !important;
    }
}

/* ==========================================================================
   Global Mobile Overflow Prevention
   ========================================================================== */

/* Ensure all main content stays within viewport */
.home-page,
main {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ==========================================================================
   Hero Slider Mobile Fixes
   ========================================================================== */

/* Mobile viewport constraints */
@media (max-width: 768px) {
    /* Hero container - prevent any overflow */
    .hero-slider-video-banner {
        position: relative;
        width: 100%;
        max-width: 100vw;
        overflow: hidden;
    }
    
    /* Video player - ensure it covers but doesn't cause overflow */
    .hero-video-player {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    
    .hero-video-player video {
        position: absolute;
        top: 50%;
        left: 50%;
        min-width: 100%;
        min-height: 100%;
        width: auto;
        height: auto;
        transform: translate(-50%, -50%);
        object-fit: cover;
    }
    
    /* Hero content wrapper - proper mobile padding */
    .hero-content-wrapper {
        position: relative;
        z-index: 10;
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 100%;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 80px 20px 100px 20px;
        box-sizing: border-box;
    }
    
    /* Hero subtitle */
    .hero-subtitle {
        font-size: 11px;
        letter-spacing: 1.5px;
        margin-bottom: 12px;
        word-wrap: break-word;
    }
    
    /* Hero title - responsive sizing with word wrap */
    .hero-title {
        font-size: clamp(28px, 7vw, 40px);
        line-height: 1.15;
        margin: 0 0 12px 0;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
        max-width: 100%;
    }
    
    /* Hero description - contained width */
    .hero-description {
        font-size: 14px;
        line-height: 1.5;
        margin: 0 0 24px 0;
        max-width: 100%;
        word-wrap: break-word;
    }
    
    /* Hero CTA button - ensure it doesn't overflow */
    .hero-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 12px 20px;
        font-size: 13px;
        max-width: 100%;
        box-sizing: border-box;
        white-space: nowrap;
    }
    
    /* Long button text handling */
    .hero-btn span,
    .hero-btn {
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Progress indicators - centered and responsive */
    .progress-indicators {
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        z-index: 20;
        width: auto;
        max-width: calc(100% - 40px);
        padding: 0 10px;
        box-sizing: border-box;
    }
    
    /* Slider dots - smaller on mobile */
    .hero-slider-dot {
        width: 28px;
        height: 3px;
        flex-shrink: 0;
    }
    
    /* Play/pause button - touch friendly */
    .play-pause-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        flex-shrink: 0;
    }
    
    /* Gradient overlay - adjust for mobile readability */
    .hero-slider-item::after {
        background: linear-gradient(
            to top,
            rgba(0, 0, 0, 0.8) 0%,
            rgba(0, 0, 0, 0.6) 30%,
            rgba(0, 0, 0, 0.4) 60%,
            rgba(0, 0, 0, 0.3) 100%
        );
    }
}

/* Extra small screens (< 360px) */
@media (max-width: 360px) {
    .hero-content-wrapper {
        padding: 70px 16px 90px 16px;
    }
    
    .hero-title {
        font-size: 24px;
    }
    
    .hero-description {
        font-size: 13px;
    }
    
    .hero-btn {
        padding: 10px 16px;
        font-size: 12px;
    }
    
    .hero-slider-dot {
        width: 24px;
    }
}

/* ==========================================================================
   Header Mobile Fixes
   ========================================================================== */
@media (max-width: 1023px) {
    .site-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 9999;
    }
    
    .header__inner {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 70px;
        padding: 0 16px;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Logo container - ensure visibility */
    .header__logo {
        display: flex;
        align-items: center;
        flex-shrink: 0;
        max-width: 50%;
    }
    
    /* Logo image sizing */
    .header__logo img {
        height: 60px;
        width: auto;
        max-width: 100%;
        object-fit: contain;
    }
    
    /* Mobile toggle button - proper touch target */
    .mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        padding: 0;
        margin: 0;
        background: transparent;
        border: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-toggle .icon {
        width: 24px;
        height: 24px;
    }
}

/* ==========================================================================
   Mobile Navigation Improvements
   ========================================================================== */
@media (max-width: 1023px) {
    .mobile-nav {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 320px;
        background: #FFFFFF;
        z-index: 10000;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .mobile-nav.is-open {
        transform: translateX(0);
    }
    
    .mobile-nav__header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        border-bottom: 1px solid #E5E5E5;
        position: sticky;
        top: 0;
        background: #FFFFFF;
        z-index: 1;
    }
    
    /* Close button - proper touch target */
    .mobile-nav__close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        background: transparent;
        border: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-nav__content {
        padding: 16px;
    }
    
    /* Navigation links - proper touch targets */
    .mobile-nav__link {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 0;
        min-height: 48px;
        font-size: 16px;
        font-weight: 500;
        color: #171717;
        text-decoration: none;
        border-bottom: 1px solid #F5F5F5;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Submenu links */
    .mobile-submenu__link {
        display: block;
        padding: 12px 16px;
        min-height: 44px;
        font-size: 14px;
        color: #525252;
        text-decoration: none;
    }
    
    /* Mobile overlay */
    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-overlay.is-visible {
        opacity: 1;
        visibility: visible;
    }
}

/* ==========================================================================
   Homepage Sections Mobile Fixes
   ========================================================================== */
@media (max-width: 768px) {
    /* Protection Solutions Section */
    .home-solutions__inner {
        padding: 0 16px;
    }
    
    /* OEM Partners Section - Critical overflow fix */
    .home-oem {
        padding: 48px 16px !important;
        overflow: hidden;
        max-width: 100vw;
        box-sizing: border-box;
    }
    
    .home-oem__inner {
        max-width: 100%;
        overflow: hidden;
    }
    
    .home-oem__header {
        margin-bottom: 32px;
    }
    
    .home-oem__label {
        font-size: 10px;
        letter-spacing: 2px;
    }
    
    .home-oem__title {
        font-size: clamp(24px, 5vw, 32px);
    }
    
    /* Factory Applied Section - Critical fixes */
    .home-oem__factory {
        padding: 20px 16px !important;
        border-radius: 16px;
        max-width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }
    
    .home-oem__factory-content {
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }
    
    .home-oem__factory-text {
        max-width: 100%;
    }
    
    .home-oem__factory-desc {
        font-size: 14px;
        line-height: 1.6;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* Factory logos grid - prevent overflow */
    .home-oem__factory-logos {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        max-width: 100%;
    }
    
    .factory-logo {
        padding: 16px 12px !important;
        aspect-ratio: 16 / 10;
        min-width: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .factory-logo img {
        max-width: 90%;
        max-height: 45px;
        width: auto;
        height: auto;
        object-fit: contain;
    }
    
    /* OEM Cards */
    .home-oem__official-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    .oem-card {
        padding: 24px 16px;
    }
    
    .oem-card__logo img {
        max-width: 120px;
    }
    
    /* Royal Treatment Section */
    .home-royal__content {
        padding: 48px 20px;
        text-align: center;
    }
    
    .home-royal__title {
        font-size: clamp(24px, 6vw, 36px);
    }
    
    .home-royal__text {
        font-size: 14px;
        max-width: 100%;
    }
    
    /* Articles Section */
    .home-articles__inner {
        padding: 48px 16px;
    }
    
    .home-articles__header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
        margin-bottom: 24px;
    }
    
    .home-articles__grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

/* Extra small screens */
@media (max-width: 400px) {
    .home-oem__factory {
        padding: 16px 12px !important;
    }
    
    .home-oem__factory-logos {
        gap: 8px !important;
    }
    
    .factory-logo {
        padding: 12px 10px !important;
    }
    
    .factory-logo img {
        max-height: 40px;
    }
}

/* ==========================================================================
   Footer Mobile Fixes
   ========================================================================== */
@media (max-width: 768px) {
    .site-footer {
        overflow-x: hidden;
    }
    
    .footer__inner {
        padding: 40px 16px 24px;
    }
    
    .footer__grid {
        grid-template-columns: 1fr;
        gap: 32px;
    }
    
    /* Stock ticker in footer */
    .footer__stock {
        max-width: 100%;
        overflow: hidden;
    }
    
    .footer__bottom {
        flex-direction: column;
        gap: 16px;
        text-align: center;
        padding: 20px 16px;
    }
    
    .footer__legal {
        flex-wrap: wrap;
        justify-content: center;
        gap: 12px;
    }
    
    .footer__legal a {
        padding: 8px 12px;
        font-size: 12px;
    }
}

/* ==========================================================================
   Touch Interaction Improvements
   ========================================================================== */
@media (max-width: 1023px) {
    /* Remove hover states on touch devices */
    @media (hover: none) {
        .btn:hover,
        .card:hover,
        .coverage-card:hover .coverage-card__image img,
        .oem-card:hover {
            transform: none;
        }
    }
    
    /* Active states for touch feedback */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    .mobile-nav__link:active,
    .mobile-submenu__link:active {
        background-color: #F5F5F5;
    }
    
    /* Prevent text selection on interactive elements */
    .btn,
    .mobile-toggle,
    .mobile-nav__close,
    .hero-btn,
    .play-pause-btn {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ==========================================================================
   Safe Area Insets (for notched devices)
   ========================================================================== */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .hero-content-wrapper {
            padding-left: max(20px, env(safe-area-inset-left));
            padding-right: max(20px, env(safe-area-inset-right));
            padding-bottom: max(100px, calc(100px + env(safe-area-inset-bottom)));
        }
        
        .site-header .header__inner {
            padding-left: max(16px, env(safe-area-inset-left));
            padding-right: max(16px, env(safe-area-inset-right));
        }
        
        .mobile-nav {
            padding-bottom: env(safe-area-inset-bottom);
        }
        
        .site-footer .footer__inner {
            padding-left: max(16px, env(safe-area-inset-left));
            padding-right: max(16px, env(safe-area-inset-right));
        }
        
        .progress-indicators {
            bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
        }
    }
}

/* ==========================================================================
   Landscape Mode Fixes
   ========================================================================== */
@media (max-width: 896px) and (orientation: landscape) {
    .hero-slider-video-banner {
        height: 100svh;
        min-height: 400px;
    }
    
    .hero-content-wrapper {
        padding-top: 60px;
        padding-bottom: 60px;
        justify-content: center;
    }
    
    .hero-title {
        font-size: clamp(24px, 5vw, 32px);
        margin-bottom: 8px;
    }
    
    .hero-description {
        margin-bottom: 16px;
    }
    
    .progress-indicators {
        bottom: 12px;
    }
}

/* ==========================================================================
   Accessibility & Focus States
   ========================================================================== */
@media (max-width: 1023px) {
    /* Visible focus states for keyboard navigation */
    .mobile-toggle:focus-visible,
    .mobile-nav__close:focus-visible,
    .mobile-nav__link:focus-visible,
    .hero-btn:focus-visible,
    .btn:focus-visible {
        outline: 2px solid #FDB521;
        outline-offset: 2px;
    }
    
    /* Reduce motion for users who prefer it */
    @media (prefers-reduced-motion: reduce) {
        .hero-slider-item {
            transition: opacity 0.2s ease-out;
        }
        
        .mobile-nav {
            transition: transform 0.2s ease;
        }
        
        .mobile-overlay {
            transition: opacity 0.2s ease, visibility 0.2s ease;
        }
    }
}
