/**
 * Michigan Diagnostics - Responsive Fixes & Mobile Optimization
 * Fixes navigation menu wrapping and adds comprehensive mobile/tablet support
 */

/* ========================================
   FIX: NAVIGATION MENU WRAPPING
   ======================================== */

/* Ensure navigation items stay on one row */
.main-navigation ul {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
}

.main-navigation ul li {
    margin: 0;
    white-space: nowrap;
}

.main-navigation ul li a {
    padding: 8px 8px !important;
    font-size: 13px !important;
    display: inline-block;
}

/* Reduce padding on smaller desktop screens */
@media (max-width: 1200px) {
    .main-navigation ul li a {
        padding: 10px 10px !important;
        font-size: 14px;
    }
}

/* Submenu styling */
.main-navigation ul ul {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 220px;
    z-index: 1000;
    flex-direction: column;
}

.main-navigation ul li:hover > ul,
.main-navigation ul li:focus-within > ul {
    display: flex;
}

.main-navigation ul ul li {
    width: 100%;
    white-space: normal;
}

.main-navigation ul ul li a {
    padding: 12px 20px !important;
    display: block;
    border-bottom: 1px solid #E0E0E0;
    font-size: 14px;
}

.main-navigation ul ul li:last-child a {
    border-bottom: none;
}

/* ========================================
   RESPONSIVE HEADER - DESKTOP
   ======================================== */

.site-header {
    position: relative;
}

.site-header .col-full {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    max-width: 1400px;
    padding: 0 30px;
}

/* Logo area */
.site-branding {
    flex: 0 0 auto;
    max-width: 250px;
}

.custom-logo {
    max-height: 70px !important;
}

/* Navigation area */
.main-navigation {
    flex: 1 1 auto;
    display: flex;
    justify-content: flex-end;
}

/* Top bar responsive */
.top-bar .col-full {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    gap: 15px;
}

.top-bar .button {
    background-color: #4DB8E8 !important;
    color: #FFFFFF !important;
    border: 2px solid #4DB8E8 !important;
    padding: 8px 16px !important;
    font-size: 13px !important;
    white-space: nowrap;
}

/* ========================================
   TABLET OPTIMIZATION (768px - 1024px)
   ======================================== */

@media (max-width: 1024px) {
    /* Header adjustments */
    .site-header .col-full {
        padding: 0 20px;
    }

    .site-branding {
        max-width: 200px;
    }

    .custom-logo {
        max-height: 60px !important;
    }

    /* Hero section */
    .hero-search h1 {
        font-size: 36px;
    }

    .hero-search p {
        font-size: 17px;
    }

    /* Category grid */
    .category-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
        padding: 30px 0;
    }

    .category-card {
        padding: 25px 15px;
    }

    .category-card h3 {
        font-size: 18px;
    }

    /* Trust badges */
    .trust-badges-wrapper {
        gap: 15px;
    }

    .trust-badge {
        font-size: 13px;
    }

    /* Footer */
    .footer-widgets {
        grid-template-columns: repeat(2, 1fr);
        gap: 25px;
    }

    /* WooCommerce products */
    .woocommerce ul.products {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* ========================================
   MOBILE OPTIMIZATION (up to 767px)
   ======================================== */

@media (max-width: 767px) {
    /* Hide desktop navigation, show mobile menu toggle */
    .main-navigation {
        display: none;
    }

    .menu-toggle {
        display: block !important;
        background: #1A2E5A;
        color: white;
        border: none;
        padding: 10px 20px;
        border-radius: 4px;
        cursor: pointer;
        font-weight: 500;
        font-size: 16px;
        margin-left: auto;
    }

    .main-navigation.toggled {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        z-index: 99999;
        overflow-y: auto;
        padding: 20px;
    }

    .main-navigation.toggled ul {
        flex-direction: column;
        align-items: stretch;
    }

    .main-navigation.toggled ul li {
        width: 100%;
        border-bottom: 1px solid #E0E0E0;
    }

    .main-navigation.toggled ul li a {
        padding: 15px 10px !important;
        display: block;
        font-size: 16px !important;
    }

    .main-navigation.toggled ul ul {
        position: static;
        display: none;
        box-shadow: none;
        padding-left: 20px;
        background: #F5F5F5;
    }

    .main-navigation.toggled ul li.focus > ul,
    .main-navigation.toggled ul li:hover > ul {
        display: flex;
    }

    /* Close button for mobile menu */
    .main-navigation.toggled::before {
        content: '✕ Close';
        display: block;
        padding: 15px;
        background: #1A2E5A;
        color: white;
        text-align: right;
        font-weight: 600;
        font-size: 18px;
        margin: -20px -20px 20px -20px;
        cursor: pointer;
    }

    /* Header adjustments */
    .site-header .col-full {
        padding: 0 15px;
    }

    .site-branding {
        max-width: 180px;
    }

    .custom-logo {
        max-height: 50px !important;
    }

    /* Top bar mobile */
    .top-bar {
        padding: 10px 0;
        font-size: 12px;
    }

    .top-bar .col-full {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .top-bar-menu {
        flex-direction: column;
        gap: 8px;
    }

    .top-bar .button {
        padding: 10px 20px !important;
        font-size: 14px !important;
    }

    /* Hero section mobile */
    .hero-search {
        padding: 30px 15px;
    }

    .hero-search h1 {
        font-size: 24px;
        line-height: 1.3;
    }

    .hero-search p {
        font-size: 15px;
    }

    .hero-subtitle {
        font-size: 14px !important;
    }

    .hero-buttons {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .hero-buttons .button {
        width: 100%;
        padding: 14px 20px !important;
    }

    /* Search bar mobile */
    .search-bar-wrapper {
        padding: 15px 0;
    }

    .search-bar-wrapper form {
        flex-direction: column;
        border-radius: 8px;
    }

    .search-bar-wrapper input[type="search"] {
        border-radius: 8px 8px 0 0 !important;
        border-right: 2px solid var(--border-light) !important;
        padding: 15px 20px;
        font-size: 15px;
    }

    .search-bar-wrapper button[type="submit"] {
        border-radius: 0 0 8px 8px !important;
        padding: 15px 20px;
        font-size: 16px;
    }

    /* Category grid mobile */
    .category-section {
        padding: 40px 15px !important;
    }

    .category-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 20px 0;
    }

    .category-card {
        padding: 20px 10px;
    }

    .category-card .category-icon {
        font-size: 36px !important;
        margin-bottom: 8px !important;
    }

    .category-card h3 {
        font-size: 14px;
        margin: 10px 0 6px;
    }

    .category-card .category-description {
        font-size: 11px !important;
        margin: 6px 0 !important;
    }

    .category-card .product-count {
        font-size: 12px;
    }

    /* Featured products mobile */
    .featured-products-section {
        padding: 40px 15px !important;
    }

    /* Trust badges mobile */
    .trust-badges {
        padding: 20px 15px;
    }

    .trust-badges-wrapper {
        flex-direction: column;
        gap: 12px;
    }

    .trust-badge {
        font-size: 13px;
    }

    /* About snippet mobile */
    .about-snippet {
        padding: 40px 15px !important;
    }

    .about-snippet > div {
        grid-template-columns: 1fr !important;
        gap: 30px !important;
    }

    .about-snippet h2 {
        font-size: 26px !important;
    }

    .about-snippet p {
        font-size: 15px !important;
    }

    .company-stats h3 {
        font-size: 20px !important;
    }

    .stat-item > div:first-child {
        font-size: 28px !important;
    }

    /* Custom synthesis CTA mobile */
    .custom-synthesis-cta {
        padding: 40px 15px !important;
    }

    .custom-synthesis-cta h2 {
        font-size: 28px !important;
    }

    .custom-synthesis-cta p {
        font-size: 16px !important;
    }

    /* Latest resources mobile */
    .latest-resources {
        padding: 40px 15px !important;
    }

    .latest-resources > div {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    /* Footer mobile */
    .site-footer {
        padding: 30px 15px 15px;
    }

    .footer-widgets {
        grid-template-columns: 1fr;
        gap: 25px;
    }

    .footer-copyright {
        font-size: 12px;
    }

    /* WooCommerce products mobile */
    .woocommerce ul.products {
        grid-template-columns: 1fr !important;
    }

    .woocommerce ul.products li.product {
        padding: 15px;
    }

    /* Forms mobile */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="url"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 14px 18px;
    }

    /* Buttons mobile */
    .button,
    .wp-block-button__link,
    button[type="submit"],
    .woocommerce #respond input#submit,
    .woocommerce a.button,
    .woocommerce button.button,
    .woocommerce input.button {
        padding: 14px 24px;
        font-size: 16px;
        width: 100%;
        text-align: center;
    }

    /* Product page mobile */
    .single-product .product {
        display: flex;
        flex-direction: column;
    }

    .single-product .product .images {
        width: 100% !important;
        margin-bottom: 20px;
    }

    .single-product .product .summary {
        width: 100% !important;
    }

    /* Tables mobile - make scrollable */
    .woocommerce-page table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* ========================================
   SMALL MOBILE (up to 480px)
   ======================================== */

@media (max-width: 480px) {
    /* Even smaller text for tiny screens */
    .hero-search h1 {
        font-size: 20px;
    }

    .category-grid {
        grid-template-columns: 1fr;
    }

    .category-card h3 {
        font-size: 16px;
    }

    /* Section headers */
    .section-header h2 {
        font-size: 28px !important;
    }

    .section-header p {
        font-size: 15px !important;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .main-navigation ul li a,
    .button,
    a.button,
    input[type="submit"] {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Remove hover effects on touch devices */
    .category-card:hover {
        transform: none;
    }

    /* Add tap highlight */
    a, button, input[type="submit"] {
        -webkit-tap-highlight-color: rgba(77, 184, 232, 0.3);
    }
}

/* ========================================
   LANDSCAPE MOBILE OPTIMIZATION
   ======================================== */

@media (max-width: 767px) and (orientation: landscape) {
    .hero-search {
        padding: 20px 15px;
    }

    .hero-search h1 {
        font-size: 20px;
    }

    .hero-search p {
        font-size: 14px;
        margin-bottom: 15px;
    }

    .search-bar-wrapper {
        padding: 10px 0;
    }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* Reduce animations on mobile for performance */
@media (max-width: 767px) {
    * {
        transition-duration: 0.2s !important;
    }

    .category-card:hover .category-icon {
        transform: scale(1.05);
    }
}

/* ========================================
   ACCESSIBILITY - FOCUS STATES
   ======================================== */

.main-navigation a:focus,
.button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #4DB8E8;
    outline-offset: 2px;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #1A2E5A;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 100000;
}

.skip-link:focus {
    top: 0;
}

/* NUCLEAR HEADER FIX */
.woocommerce-active .site-header .site-branding,
.site-header .site-branding {
    width: 200px !important;
    min-width: 200px !important;
    max-width: 200px !important;
    float: none !important;
    flex-shrink: 0 !important;
}

.woocommerce-active .site-header .main-navigation,
.site-header .main-navigation {
    width: auto !important;
    float: none !important;
    clear: none !important;
    flex: 1 1 auto !important;
}

.site-header-content {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    width: 100% !important;
}

.site-header .custom-logo-link img,
.site-header .custom-logo {
    width: 180px !important;
    max-width: 180px !important;
    height: auto !important;
}

/* Force nav items to fit on one row */
.main-navigation ul.menu > li > a,
.main-navigation ul.nav-menu > li > a {
    padding: 8px 8px !important;
    font-size: 13px !important;
}

.main-navigation ul li a {
    padding: 8px 8px !important;
    font-size: 13px !important;
}

.header-search {
    flex-shrink: 0 !important;
}