/* ==========================================================================
   CG HUNTER MOBILE OPTIMIZATION PATCH
   Target: Mobile Devices Only (max-width: 768px)
   Strategy: Overwrite styles with !important to ensure mobile-specific layout
   ========================================================================== */

@media (max-width: 768px) {

    /* --- 1. GRID LAYOUT OPTIMIZATION (Double Column) --- */
    .grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        padding: 0 5px !important;
    }

    .main-container {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .card {
        border-radius: 12px !important; /* Slightly smaller radius */
        box-shadow: 0 2px 5px rgba(0,0,0,0.05) !important;
    }

    .card-img {
        aspect-ratio: 4/3 !important; /* Taller images for better visibility */
    }

    .card-content {
        padding: 10px !important;
    }

    .card-title {
        font-size: 0.85rem !important;
        line-height: 1.3 !important;
        height: 2.6em; /* Limit to 2 lines */
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        margin-bottom: 5px !important;
    }

    .card-cat {
        font-size: 0.65rem !important;
        margin-bottom: 4px !important;
    }

    .card-date {
        font-size: 0.7rem !important;
    }
    
    /* Hide ID badge on mobile grid to save space, show in modal instead */
    .card-id-badge {
        display: none !important;
    }
    
    /* Adjust Premium Badge */
    .premium-badge {
        font-size: 0.6rem !important;
        padding: 2px 4px !important;
        top: 5px !important;
        left: 5px !important;
    }

    /* --- 2. MODAL OPTIMIZATION (Full Screen Immersive) --- */
    .modal-box {
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        flex-direction: column !important;
        transform: none !important; /* Remove scale animation for performance */
        top: 0 !important;
        margin: 0 !important;
    }

    .modal-wrap {
        padding: 0 !important;
        align-items: flex-start !important; /* Align top */
        z-index: 9999 !important; /* Ensure on top of everything */
    }

    .modal-image-area {
        width: 100% !important;
        height: 40vh !important; /* Fixed height for image area */
        background: #000 !important;
        flex-shrink: 0 !important;
        position: relative !important;
    }

    .modal-image-area img {
        object-fit: contain !important; /* Ensure full image is visible */
    }

    .modal-content-area {
        width: 100% !important;
        height: 60vh !important; /* Remaining height */
        padding: 20px !important;
        border-radius: 20px 20px 0 0 !important; /* Rounded top corners for sheet look */
        margin-top: -20px !important; /* Overlap image slightly */
        background: var(--bg-card) !important;
        position: relative !important;
        z-index: 10 !important;
        overflow-y: auto !important;
        padding-bottom: 80px !important; /* Space for fixed bottom actions if any */
    }

    /* Floating Close Button */
    .m-close {
        top: 15px !important;
        right: 15px !important;
        background: rgba(0, 0, 0, 0.6) !important;
        color: white !important;
        width: 36px !important;
        height: 36px !important;
        font-size: 1.2rem !important;
        backdrop-filter: blur(4px);
        border: 1px solid rgba(255,255,255,0.2) !important;
        z-index: 20 !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Floating Heart Button */
    .m-fav-btn {
        top: 15px !important;
        left: 15px !important;
        background: rgba(0, 0, 0, 0.6) !important;
        color: white !important;
        width: 36px !important;
        height: 36px !important;
        font-size: 1rem !important;
        backdrop-filter: blur(4px);
        border: 1px solid rgba(255,255,255,0.2) !important;
        z-index: 20 !important;
    }
    
    .m-fav-btn.active {
        color: #ff7675 !important;
        background: rgba(255, 255, 255, 0.9) !important;
    }

    .m-title {
        font-size: 1.3rem !important;
        margin-top: 5px !important;
        line-height: 1.3 !important;
    }
    
    .m-desc {
        font-size: 0.95rem !important;
        line-height: 1.6 !important;
    }

    /* --- 3. PAGINATION OPTIMIZATION (Simplified) --- */
    .pagination {
        gap: 5px !important;
        flex-wrap: wrap !important;
        margin-top: 20px !important;
        margin-bottom: 40px !important;
    }

    .page-btn {
        padding: 8px 14px !important;
        font-size: 0.9rem !important;
        min-width: 40px !important;
        height: 40px !important;
        border-radius: 8px !important;
    }

    .pagination-jump {
        display: none !important; /* Hide jump input on mobile */
    }
    
    /* Hide dots if too many */
    .page-dots { display: none !important; }

    /* --- 4. HEADER OPTIMIZATION --- */
    .top-header {
        padding: 0 10px !important;
        height: 60px !important;
    }

    .mobile-toggle {
        font-size: 1.2rem !important;
        padding: 10px !important; /* Larger touch target */
    }

    .header-right {
        gap: 8px !important;
        flex: 1 !important;
        justify-content: flex-end !important;
        display: flex !important;
        align-items: center !important;
    }

    /* Optimize Search Bar */
    .search-container {
        height: 36px !important;
        padding: 0 8px !important;
        width: auto !important;
        flex: 1 !important;
        max-width: 100% !important;
    }

    #header-search-scope {
        max-width: 60px !important; /* Shrink select */
        font-size: 0.8rem !important;
        padding: 0 !important;
    }

    .search-container input {
        font-size: 0.9rem !important;
        width: 100% !important; /* Allow shrinking */
        min-width: 50px !important;
    }

    /* --- RESTORE LOGIN BUTTON ON MOBILE HEADER --- */
    #navAuth {
        display: flex !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        min-width: auto !important;
        margin-left: 5px !important;
    }

    /* Style the login button as a simple icon circle */
    .nav-auth-btn {
        width: 36px !important;
        height: 36px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: var(--primary-color) !important;
        color: white !important;
        font-size: 0 !important; /* Hide text */
        box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3) !important;
    }

    /* Add icon via pseudo-element since text is hidden */
    .nav-auth-btn::before {
        content: "\f007"; /* FontAwesome User Icon */
        font-family: "Font Awesome 6 Free";
        font-weight: 900;
        font-size: 1rem !important;
    }

    /* If user is logged in, show avatar or different icon */
    .user-welcome {
        display: none !important; /* Hide welcome text on mobile header */
    }

    
    /* --- 5. SIDEBAR OPTIMIZATION --- */
    .sidebar {
        width: 80% !important; /* Not full width, but wider than desktop px */
        max-width: 300px !important;
    }
    
    .menu-item {
        padding: 14px 20px !important; /* Larger touch targets */
    }
    
    /* --- 6. HERO SECTION MOBILE --- */
    #hero-section {
        height: auto !important;
        min-height: 100vh !important;
        overflow-y: visible !important;
        position: relative !important;
        padding-bottom: 120px !important; /* Ensure space for footer */
        padding-top: 80px !important; /* Add top padding to avoid header overlap */
    }

    .hero-footer {
        position: relative !important;
        margin-top: 40px !important;
        bottom: auto !important;
        left: auto !important;
        width: 100% !important;
    }

    .hero-content {
        padding: 20px 15px !important;
        width: 100% !important;
    }
    
    .hero-title {
        font-size: 2rem !important;
        margin-bottom: 20px !important;
    }

    .hero-subtitle {
        font-size: 0.95rem !important;
        margin-bottom: 30px !important;
        padding: 0 10px !important;
        line-height: 1.6 !important;
    }
    
    /* --- COMPACT SEARCH BAR (Expandable) --- */
    .hero-input-wrapper {
        width: 50px !important; /* Start as a circle/icon */
        height: 50px !important;
        border-radius: 50% !important;
        background: var(--bg-card) !important;
        box-shadow: 0 4px 15px rgba(0,0,0,0.1) !important;
        padding: 0 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        margin: 0 auto 30px !important; /* Center and add margin */
        transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important; /* Bouncy transition */
        overflow: hidden !important;
        cursor: pointer !important;
        position: relative !important;
        z-index: 100 !important;
        border: 1px solid var(--border-color) !important;
    }
    
    /* Initial State: Hide children */
    .hero-input-wrapper:not(.expanded) > * {
        display: none !important;
    }

    /* Initial State: Show Icon via Pseudo-element or existing icon */
    /* We use the existing .fa-search icon but style it specifically */
    .hero-input-wrapper:not(.expanded) .hero-search-icon {
        display: block !important;
        position: static !important;
        font-size: 1.2rem !important;
        color: var(--primary-color) !important;
        margin: 0 !important;
        pointer-events: none !important; /* Let click pass to wrapper */
    }

    /* Expanded State */
    .hero-input-wrapper.expanded {
        width: 100% !important;
        height: auto !important;
        border-radius: 24px !important;
        padding: 20px !important;
        flex-direction: column !important;
        gap: 15px !important;
        background: var(--bg-card) !important;
        box-shadow: 0 20px 50px rgba(0,0,0,0.2) !important;
        align-items: stretch !important;
        border-color: var(--primary-color) !important;
    }
    
    .hero-input-wrapper.expanded #hero-search-scope {
        display: block !important; /* Show scope in expanded mode */
        width: 100% !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 12px !important;
        padding: 0 10px !important;
        height: 45px !important;
        margin-bottom: 5px !important;
        background: #f8f9fa !important;
    }

    .hero-input-wrapper.expanded #hero-search-input {
        display: block !important;
        width: 100% !important;
        height: 50px !important;
        padding: 0 15px !important;
        text-align: left !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 12px !important;
        background: #f8f9fa !important;
        font-size: 1rem !important;
    }
    
    .hero-input-wrapper.expanded #hero-search-btn {
        display: block !important;
        width: 100% !important;
        position: static !important;
        margin-top: 10px !important;
        height: 45px !important;
        border-radius: 12px !important;
        font-weight: 700 !important;
        letter-spacing: 1px !important;
        box-shadow: 0 5px 15px rgba(108, 92, 231, 0.3) !important;
    }
    
    .hero-input-wrapper.expanded .hero-search-icon {
        display: none !important;
    }

    /* Hero Tags Optimization */
    .hero-tags {
        gap: 8px !important;
        justify-content: center !important;
        margin-bottom: 40px !important;
    }

    .hero-tag {
        padding: 8px 16px !important;
        font-size: 0.85rem !important;
        background: rgba(255,255,255,0.8) !important;
        border: 1px solid rgba(108, 92, 231, 0.2) !important;
        box-shadow: 0 2px 5px rgba(0,0,0,0.05) !important;
    }

