/* Mobile Responsive Fixes - Shared across all pages */

/* Prevent horizontal scrolling */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Container and layout fixes */
* {
    box-sizing: border-box;
}

/* Ensure most containers don't exceed viewport width, but preserve nav functionality */
@media (max-width: 768px) {
    .container {
        width: 100%;
        max-width: 100vw;
        padding-left: 1rem;
        padding-right: 1rem;
        margin-left: auto;
        margin-right: auto;
    }
    
    /* Specific navigation container fixes */
    nav .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        width: 100% !important;
        max-width: none !important;
    }
}

/* Fix grid layouts on mobile */
@media (max-width: 768px) {
    /* Force single column layout on mobile for problematic grids */
    .grid.md\\:grid-cols-2,
    .grid.md\\:grid-cols-3,
    .grid.lg\\:grid-cols-2,
    .grid.lg\\:grid-cols-3,
    .grid.lg\\:grid-cols-4,
    .grid.lg\\:grid-cols-5,
    .grid.lg\\:grid-cols-6 {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    /* Ensure grid items don't overflow */
    .grid > * {
        min-width: 0;
        max-width: 100%;
    }
}

/* Fix flexbox layouts that might cause overflow */
@media (max-width: 768px) {
    .flex.flex-col.sm\\:flex-row,
    .flex.flex-wrap {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .flex.justify-center.gap-8,
    .flex.justify-center.gap-6,
    .flex.justify-center.gap-4 {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }
}

/* Text and heading responsive fixes */
@media (max-width: 768px) {
    /* Scale down large text sizes */
    .text-5xl, .text-6xl, .text-7xl {
        font-size: 2.5rem !important;
        line-height: 1.2 !important;
    }
    
    .text-4xl {
        font-size: 2rem !important;
        line-height: 1.3 !important;
    }
    
    .text-3xl {
        font-size: 1.75rem !important;
        line-height: 1.3 !important;
    }
    
    .text-2xl {
        font-size: 1.5rem !important;
        line-height: 1.4 !important;
    }
    
    .text-xl {
        font-size: 1.125rem !important;
        line-height: 1.5 !important;
    }
}

/* Button and interactive element fixes */
@media (max-width: 768px) {
    /* Make buttons stack vertically */
    .flex.flex-col.sm\\:flex-row.gap-4 button,
    .flex.flex-col.sm\\:flex-row.gap-4 a {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Ensure buttons don't overflow */
    button, .btn, a[class*="bg-"] {
        max-width: 100% !important;
        word-wrap: break-word !important;
        white-space: normal !important;
    }
}

/* Image and media responsive fixes */
@media (max-width: 768px) {
    img, video, iframe {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Fix logo and icon containers */
    .w-16, .w-20, .h-16, .h-20 {
        width: 3rem !important;
        height: 3rem !important;
    }
}

/* Navigation fixes */
@media (max-width: 768px) {
    /* Ensure navigation bar elements are properly sized */
    nav {
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    /* Navigation content should not be truncated */
    nav .flex.justify-between.items-center {
        width: 100% !important;
        flex-wrap: nowrap !important;
    }
    
    /* Brand name should not be cut off */
    nav .flex-shrink-0 a {
        white-space: nowrap !important;
        min-width: max-content !important;
        overflow: visible !important;
        text-overflow: unset !important;
    }
    
    /* Ensure the brand container has enough space */
    nav .flex-shrink-0 {
        flex-shrink: 0 !important;
        min-width: max-content !important;
        overflow: visible !important;
    }
    
    /* Make sure the navigation container doesn't cut off content */
    nav .container {
        overflow: visible !important;
    }
    
    /* Fix mobile menu positioning */
    #mobile-menu {
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
    }
    
    /* Mobile dropdown content fixes */
    .dropdown-content {
        position: fixed !important;
        left: 1rem !important;
        right: 1rem !important;
        width: auto !important;
        max-width: calc(100vw - 2rem) !important;
        min-width: auto !important;
    }
}

/* Form and input fixes */
@media (max-width: 768px) {
    input, textarea, select {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Modal fixes */
    .fixed.inset-0 > div {
        max-width: calc(100vw - 2rem) !important;
        margin: 1rem !important;
    }
}

/* Table responsive fixes */
@media (max-width: 768px) {
    table {
        display: block !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
    }
    
    tbody, thead, tr {
        display: block !important;
    }
    
    th, td {
        display: inline-block !important;
        vertical-align: top !important;
    }
}

/* Code block fixes */
@media (max-width: 768px) {
    pre, code {
        overflow-x: auto !important;
        max-width: 100% !important;
        word-break: break-all !important;
        white-space: pre-wrap !important;
    }
}

/* Padding and margin adjustments for mobile */
@media (max-width: 768px) {
    .py-20, .py-32 {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }
    
    .px-8, .px-6, .px-4 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .mb-16, .mb-12 {
        margin-bottom: 2rem !important;
    }
    
    .mb-8, .mb-6 {
        margin-bottom: 1.5rem !important;
    }
}

/* Ensure no content exceeds viewport width */
@media (max-width: 768px) {
    /* Apply overflow fixes to content sections, but not navigation */
    section:not(nav), 
    div:not(nav):not(nav *), 
    article, 
    main {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    
    /* Fix any absolute positioned elements, except navigation dropdowns and pricing section badges */
    .absolute:not(.dropdown-content):not(#pricing .absolute) {
        max-width: calc(100vw - 2rem) !important;
    }
}

/* Mobile fixes for pricing section badges */
@media (max-width: 768px) {
    /* Ensure pricing section has enough top padding for badges */
    #pricing {
        padding-top: 4rem !important;
    }
    
    /* Ensure pricing cards maintain relative positioning for badges */
    #pricing .grid > div {
        position: relative !important;
        margin-top: 3rem !important;
        z-index: 1 !important;
        overflow: visible !important;
    }
    
    /* Ensure the starter plan card (with border-2) has higher z-index and allows overflow */
    #pricing .border-2 {
        z-index: 10 !important;
        position: relative !important;
        overflow: visible !important;
    }
    
    /* Fix "Most Popular" badge positioning to be fully above the card */
    .most-popular-badge {
        position: absolute !important;
        top: -1.5rem !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 999 !important;
        display: block !important;
        visibility: visible !important;
        overflow: visible !important;
        max-width: none !important;
        white-space: nowrap !important;
        pointer-events: none !important;
    }
    
    /* Ensure the badge span styling matches desktop */
    .most-popular-badge span {
        background-color: rgb(31, 41, 55) !important;
        color: white !important;
        padding: 0.5rem 1.5rem !important;
        border-radius: 9999px !important;
        font-size: 0.875rem !important;
        font-weight: 500 !important;
        display: inline-block !important;
    }
}

/* Desktop dropdown functionality preservation */
@media (min-width: 769px) {
    /* Preserve existing dropdown styles for desktop */
    .dropdown {
        position: relative;
        display: inline-block;
    }

    .dropdown-content {
        display: none;
        position: absolute;
        background-color: hsl(0 0% 100%);
        min-width: 200px;
        box-shadow: 0 8px 16px rgba(0,0,0,0.1);
        z-index: 1000;
        border-radius: 0.5rem;
        border: 1px solid hsl(214.3 31.8% 91.4%);
        margin-top: 0;
        padding-top: 0.5rem;
        top: 100%;
        left: 0;
    }

    .dropdown-content a {
        color: hsl(222.2 47.4% 11.2%);
        padding: 12px 16px;
        text-decoration: none;
        display: block;
        transition: background-color 0.2s;
    }

    .dropdown-content a:first-child {
        border-radius: 0.5rem 0.5rem 0 0;
    }

    .dropdown-content a:last-child {
        border-radius: 0 0 0.5rem 0.5rem;
    }

    .dropdown-content a:hover {
        background-color: hsl(210 40% 96%);
    }

    .dropdown:hover .dropdown-content {
        display: block;
        animation: fadeIn 0.15s ease-in;
    }

    @keyframes fadeIn {
        from { 
            opacity: 0; 
            transform: translateY(-5px);
        }
        to { 
            opacity: 1; 
            transform: translateY(0);
        }
    }

    .dropdown-toggle {
        cursor: pointer;
    }

    .dropdown-toggle::after {
        content: '▼';
        font-size: 0.7em;
        margin-left: 0.3em;
        transition: transform 0.2s;
    }

    .dropdown:hover .dropdown-toggle::after {
        transform: rotate(180deg);
    }
}

/* Feature card hover effects - preserve on desktop */
@media (min-width: 769px) {
    .feature-card {
        transition: all 0.3s ease;
    }
    
    .feature-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    }
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
    .feature-card {
        transition: none !important;
        transform: none !important;
    }
    
    .feature-card:hover {
        transform: none !important;
    }
    
    /* Scale down organization logos on mobile */
    .logo-item img {
        max-height: 1.5rem !important;
        height: auto !important;
        width: auto !important;
    }
    
    /* Adjust logo item padding on mobile */
    .logo-item {
        padding: 0 1.5rem !important;
    }
    
    /* Hide personal learning dashboard from hero on mobile */
    #hero-learning-dashboard {
        display: none !important;
    }
}