/**
 * Mobile-First Responsive Optimization
 * Fixes mobile layout issues and maximizes screen utilization
 */

/* ===================================
   MOBILE-FIRST CONTAINER OPTIMIZATION
   =================================== */

/* Reset container padding for mobile */
.container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 12px !important; /* Minimal padding for mobile */
}

/* Mobile-first approach - start with mobile, enhance for larger screens */
@media (max-width: 480px) {
    .container {
        padding: 0 8px !important; /* Even less padding on very small screens */
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .container {
        padding: 0 16px !important; /* Slightly more padding on tablets */
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 0 24px !important; /* Tablet landscape */
        max-width: 100% !important;
    }
}

@media (min-width: 1025px) {
    .container {
        padding: 0 32px !important; /* Desktop */
        max-width: 1200px !important; /* Reasonable max-width for desktop */
        margin: 0 auto !important;
    }
}

@media (min-width: 1400px) {
    .container {
        max-width: 1400px !important; /* Large desktop */
    }
}

/* ===================================
   FULL-WIDTH SECTIONS
   =================================== */

/* Make hero sections full-width */
section[class*="hero"],
section[class*="-hero"] {
    width: 100vw !important;
    margin-left: calc(-50vw + 50%) !important;
    margin-right: calc(-50vw + 50%) !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
}

@media (min-width: 481px) {
    section[class*="hero"],
    section[class*="-hero"] {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

@media (min-width: 769px) {
    section[class*="hero"],
    section[class*="-hero"] {
        padding-left: 24px !important;
        padding-right: 24px !important;
    }
}

/* ===================================
   HEADER OPTIMIZATION
   =================================== */

.site-header {
    width: 100vw !important;
    margin-left: calc(-50vw + 50%) !important;
    margin-right: calc(-50vw + 50%) !important;
}

.header-container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 12px 8px !important; /* Minimal padding */
    margin: 0 !important;
}

@media (min-width: 481px) {
    .header-container {
        padding: 12px 16px !important;
    }
}

@media (min-width: 769px) {
    .header-container {
        padding: 16px 24px !important;
        max-width: 1200px !important;
        margin: 0 auto !important;
    }
}

/* ===================================
   CONTENT AREA OPTIMIZATION
   =================================== */

/* Main content areas should use full width */
.main-content,
.content-area,
.entry-content,
.page-content {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Remove excessive margins from content sections */
section {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
}

@media (min-width: 481px) {
    section {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

@media (min-width: 769px) {
    section {
        padding-left: 24px !important;
        padding-right: 24px !important;
    }
}

/* ===================================
   GRID LAYOUT OPTIMIZATION
   =================================== */

/* Mobile-first grid layouts */
[style*="grid-template-columns"] {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Single column on mobile */
@media (max-width: 768px) {
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    /* Specific grid overrides for mobile */
    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
    }
    
    [style*="grid-template-columns: repeat(2"] {
        grid-template-columns: 1fr !important;
    }
    
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    
    [style*="grid-template-columns: 45% 55%"] {
        grid-template-columns: 1fr !important;
    }
}

/* Tablet optimization */
@media (min-width: 769px) and (max-width: 1024px) {
    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ===================================
   COURSE CARDS & CONTENT CARDS
   =================================== */

.course-card,
.content-card,
.card {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 16px 0 !important;
}

@media (max-width: 768px) {
    .course-card,
    .content-card,
    .card {
        margin: 0 0 12px 0 !important;
    }
    
    .course-image-container {
        height: 200px !important; /* Optimized height for mobile */
    }
    
    .course-content,
    .card-content {
        padding: 16px !important;
    }
}

/* ===================================
   PRICING CARDS OPTIMIZATION
   =================================== */

.pricing-plans,
.pricing-grid {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

@media (max-width: 768px) {
    .pricing-card {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 0 16px 0 !important;
        padding: 20px !important;
    }
    
    .pricing-plans [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
}

/* ===================================
   DASHBOARD OPTIMIZATION
   =================================== */

.dashboard-content,
.dashboard-main {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

@media (max-width: 768px) {
    .dashboard-stats [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    .dashboard-section {
        padding: 16px 8px !important;
    }
}

/* ===================================
   ARCHIVE PAGES OPTIMIZATION
   =================================== */

.archive-content,
.courses-main-section {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

@media (max-width: 768px) {
    .courses-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .filters-sidebar {
        width: 100% !important;
        margin-bottom: 16px !important;
        padding: 16px !important;
    }
}

/* ===================================
   SINGLE POST/PAGE OPTIMIZATION
   =================================== */

.single-content,
.page-content {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

@media (max-width: 768px) {
    .course-content-grid,
    .single-layout {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    .course-sidebar,
    .content-sidebar {
        width: 100% !important;
        margin-top: 16px !important;
        padding: 16px !important;
    }
}

/* ===================================
   FORM OPTIMIZATION
   =================================== */

form {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

@media (max-width: 768px) {
    form input,
    form textarea,
    form select {
        width: 100% !important;
        padding: 12px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        margin-bottom: 12px !important;
    }
    
    form [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
}

/* ===================================
   BUTTON OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    .btn {
        width: 100% !important;
        padding: 12px 16px !important;
        font-size: 16px !important;
        margin-bottom: 8px !important;
    }
    
    .btn-group {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .hero-actions {
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    .hero-actions .btn {
        width: 100% !important;
    }
}

/* ===================================
   FOOTER OPTIMIZATION
   =================================== */

.site-footer {
    width: 100vw !important;
    margin-left: calc(-50vw + 50%) !important;
    margin-right: calc(-50vw + 50%) !important;
}

.footer-content {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 8px !important;
}

@media (min-width: 481px) {
    .footer-content {
        padding: 0 16px !important;
    }
}

@media (min-width: 769px) {
    .footer-content {
        padding: 0 24px !important;
        max-width: 1200px !important;
        margin: 0 auto !important;
    }
}

@media (max-width: 768px) {
    .footer-content [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }
}

/* ===================================
   TYPOGRAPHY OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    h1, .hero-title {
        font-size: 28px !important;
        line-height: 1.2 !important;
        margin-bottom: 16px !important;
    }
    
    h2 {
        font-size: 24px !important;
        line-height: 1.3 !important;
        margin-bottom: 14px !important;
    }
    
    h3 {
        font-size: 20px !important;
        line-height: 1.4 !important;
        margin-bottom: 12px !important;
    }
    
    p, li {
        font-size: 16px !important;
        line-height: 1.6 !important;
        margin-bottom: 12px !important;
    }
}

/* ===================================
   SPACING OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    section {
        padding: 24px 0 !important;
    }
    
    [style*="padding: 80px"] {
        padding: 24px 0 !important;
    }
    
    [style*="padding: 60px"] {
        padding: 24px 0 !important;
    }
    
    [style*="padding: 48px"] {
        padding: 20px 0 !important;
    }
    
    [style*="padding: 40px"] {
        padding: 20px 0 !important;
    }
}

/* ===================================
   SEARCH BAR OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    .hero-search form {
        flex-direction: column !important;
        gap: 12px !important;
        padding: 16px !important;
        width: 100% !important;
    }
    
    .hero-search input {
        width: 100% !important;
        padding: 12px 16px !important;
        font-size: 16px !important;
    }
    
    .hero-search button {
        width: 100% !important;
        padding: 12px 16px !important;
        font-size: 16px !important;
    }
}

/* ===================================
   NAVIGATION OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    .main-navigation {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* FORCE CENTER ALIGNMENT when mobile menu is open */
    .main-navigation.mobile-menu-open {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-start !important;
        text-align: center !important;
    }
    
    .main-navigation.mobile-menu-open ul,
    .main-navigation.mobile-menu-open #primary-menu {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        gap: 0 !important;
        margin: 0 auto !important;
    }
    
    .main-navigation.mobile-menu-open .menu-item {
        width: 100% !important;
        border-bottom: 1px solid var(--border-light) !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
    }
    
    .main-navigation.mobile-menu-open .menu-item a {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        padding: 16px 20px !important;
        font-size: 16px !important;
        margin: 0 auto !important;
    }
    
    /* Fallback for when menu is not open (should be hidden anyway) */
    .main-navigation ul {
        flex-direction: column !important;
        gap: 0 !important;
    }
    
    .main-navigation .menu-item {
        width: 100% !important;
        border-bottom: 1px solid var(--border-light) !important;
    }
    
    .main-navigation .menu-item a {
        display: block !important;
        padding: 16px 0 !important;
        font-size: 16px !important;
    }
}

/* ===================================
   TABLES OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    table {
        width: 100% !important;
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        white-space: nowrap !important;
    }
    
    table th,
    table td {
        padding: 8px 4px !important;
        font-size: 14px !important;
    }
}

/* ===================================
   MODAL & OVERLAY OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    .modal,
    .overlay {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        padding: 16px !important;
    }
}

/* ===================================
   VIDEO & MEDIA OPTIMIZATION
   =================================== */

@media (max-width: 768px) {
    .video-container,
    .media-container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    iframe {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* ===================================
   UTILITY CLASSES
   =================================== */

.mobile-full-width {
    width: 100vw !important;
    margin-left: calc(-50vw + 50%) !important;
    margin-right: calc(-50vw + 50%) !important;
}

.mobile-no-padding {
    padding: 0 !important;
}

.mobile-no-margin {
    margin: 0 !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
    
    .mobile-hidden {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
    
    .desktop-only {
        display: block !important;
    }
}

/* ===================================
   PERFORMANCE OPTIMIZATIONS
   =================================== */

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) {
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
    
    .course-card:hover {
        transform: none !important;
    }
}

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

@media (max-width: 768px) {
    a, button, input[type="submit"], input[type="button"] {
        min-height: 44px !important; /* iOS recommendation */
        min-width: 44px !important;
        touch-action: manipulation !important;
    }
    
    .btn {
        min-height: 48px !important;
    }
}

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

html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100% !important;
}

/* Ensure all elements respect viewport width */
* {
    max-width: 100% !important;
}

/* ===================================
   PRINT OPTIMIZATION
   =================================== */

@media print {
    .container {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    section {
        padding: 0 !important;
        margin: 0 !important;
    }
}
