/* MOBILE PRECISE FIX - PRESERVE DESKTOP LAYOUT */
/* Only fix specific issues on mobile without changing desktop design */

/* ===== MOBILE ONLY FIXES (max-width: 768px) ===== */
@media (max-width: 768px) {
    
    /* ===== 1. LOGO FIX - MOBILE ONLY ===== */
    #lgot,
    #logo1 {
        width: auto !important;
        height: auto !important;
        max-width: 80px !important;
        float: left !important;
    }
    
    #lgot img,
    #logo1 img,
    img[src*="logo.png"],
    img[src*="media/images/logo.png"] {
        width: auto !important;
        height: auto !important;
        max-width: 60px !important;
        max-height: 60px !important;
        object-fit: contain !important;
        margin-top: -5px !important;
        vertical-align: top !important;
    }
    
    /* Force override inline width/height attributes on mobile only */
    img[width="129"][height="123"],
    img[src*="logo.png"][width],
    img[src*="logo.png"][height] {
        width: auto !important;
        height: auto !important;
        max-width: 60px !important;
        max-height: 60px !important;
    }
    
    /* ===== 2. BANNER ADJUSTMENTS - MOBILE ONLY ===== */
    #banner1 {
        height: auto !important;
        min-height: 65px !important;
        padding: 5px 0 !important;
    }
    
    #banner2 {
        height: auto !important;
        padding: 5px !important;
        display: flex !important;
        align-items: flex-start !important;
    }
    
    /* ===== 3. TUVAN IMAGES FIX - MOBILE ONLY ===== */
    
    /* Only target images inside tuvan content areas */
    .tuvan-detail-content img,
    .tuvan-detail img,
    .article-detail-content img,
    #noidungtrong img {
        max-width: 100% !important;
        width: auto !important;
        height: auto !important;
        display: block !important;
        margin: 15px auto !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
        object-fit: contain !important;
    }
    
    /* Override inline width/height attributes in tuvan content */
    .tuvan-detail-content img[width],
    .tuvan-detail-content img[height],
    .tuvan-detail img[width],
    .tuvan-detail img[height],
    .article-detail-content img[width],
    .article-detail-content img[height],
    #noidungtrong img[width],
    #noidungtrong img[height] {
        width: auto !important;
        height: auto !important;
        max-width: 100% !important;
    }
    
    /* ===== 4. GRID RESPONSIVENESS - MOBILE ONLY ===== */
    
    /* Preserve desktop grid layout, only change on mobile */
    .tuvan-grid,
    .articles-grid,
    .news-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    /* ===== 5. CONTAINER OVERFLOW FIX - MOBILE ONLY ===== */
    
    /* Only fix containers that are causing overflow on mobile */
    .tuvan-page,
    .tuvan-detail,
    .article-detail,
    .technical-consultation-page {
        max-width: 100% !important;
        overflow-x: hidden !important;
        padding: 15px !important;
        box-sizing: border-box !important;
    }
    
    #noidungtrong,
    #khungchinh1,
    #khungchinh2,
    #mucgiua1,
    #mucgiua2 {
        max-width: 100% !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }
    
    /* ===== 6. HEADER TEXT PRESERVATION - MOBILE ONLY ===== */
    
    /* Ensure header text remains white on mobile gradient backgrounds */
    .tuvan-header h1,
    .tuvan-header p,
    .page-header h1,
    .page-header p {
        color: white !important;
        text-shadow: 0 2px 4px rgba(0,0,0,0.3) !important;
    }
    
    /* ===== 7. MOBILE NAVIGATION ===== */
    
    #menu1 {
        min-height: auto !important;
        padding: 5px 0 !important;
    }
    
    .nav {
        flex-direction: column !important;
        width: 100% !important;
    }
    
    .nav > li {
        width: 100% !important;
        text-align: center !important;
    }
    
    .nav > li > a,
    .nav > li > h2 > a {
        font-size: 14px !important;
        padding: 8px 15px !important;
    }
    
    /* ===== 8. TYPOGRAPHY ADJUSTMENTS - MOBILE ONLY ===== */
    
    .tuvan-header h1 {
        font-size: 2.2rem !important;
    }
    
    .tuvan-header p,
    .page-header p {
        font-size: 1rem !important;
    }
    
    .tuvan-detail-title,
    .article-detail-title {
        font-size: 1.5rem !important;
        line-height: 1.4 !important;
        word-wrap: break-word !important;
    }
    
    .tuvan-detail-content,
    .article-detail-content {
        font-size: 14px !important;
        line-height: 1.6 !important;
    }
    
    /* ===== 9. CARD ADJUSTMENTS - MOBILE ONLY ===== */
    
    .tuvan-card,
    .article-card {
        margin-bottom: 15px !important;
    }
    
    .tuvan-image,
    .article-image {
        height: 180px !important;
    }
    
    .tuvan-content,
    .article-content {
        padding: 15px !important;
    }
    
    /* ===== 10. VIDEO/IFRAME FIX - MOBILE ONLY ===== */
    
    .tuvan-detail-content iframe,
    .tuvan-detail-content video,
    .article-detail-content iframe,
    .article-detail-content video,
    #noidungtrong iframe,
    #noidungtrong video {
        max-width: 100% !important;
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 16/9 !important;
    }
    
    /* ===== 11. TABLE FIX - MOBILE ONLY ===== */
    
    .tuvan-detail-content table,
    .article-detail-content table,
    #noidungtrong table {
        overflow-x: auto !important;
        display: block !important;
        max-width: 100% !important;
        font-size: 12px !important;
        white-space: nowrap !important;
    }
    
    /* ===== 12. PREVENT HORIZONTAL SCROLL - MOBILE ONLY ===== */
    
    body,
    #wrapper {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    /* ===== 13. SEARCH BOX HIDE - MOBILE ONLY ===== */
    
    #timk2 {
        display: none !important;
    }
}

/* ===== EXTRA SMALL MOBILE (max-width: 480px) ===== */
@media (max-width: 480px) {
    
    #lgot img,
    #logo1 img,
    img[src*="logo.png"] {
        max-width: 50px !important;
        max-height: 50px !important;
        margin-top: -8px !important;
    }
    
    #banner1 {
        min-height: 55px !important;
        padding: 3px 0 !important;
    }
    
    .tuvan-page,
    .technical-consultation-page {
        padding: 10px !important;
    }
    
    .tuvan-header {
        padding: 30px 15px !important;
        margin: 10px 0 20px 0 !important;
    }
    
    .tuvan-header h1 {
        font-size: 1.8rem !important;
    }
    
    .tuvan-detail-content,
    .article-detail-content {
        font-size: 13px !important;
        padding: 10px !important;
    }
    
    .tuvan-image,
    .article-image {
        height: 160px !important;
    }
}

/* ===== DESKTOP PRESERVATION (min-width: 769px) ===== */
@media (min-width: 769px) {
    
    /* Ensure desktop layout is completely preserved */
    
    /* Desktop logo - maintain original size */
    #lgot,
    #logo1 {
        width: inherit;
        height: inherit;
        max-width: none;
    }
    
    #lgot img,
    #logo1 img {
        width: inherit;
        height: inherit;
        max-width: none;
        max-height: none;
    }
    
    /* Desktop containers - maintain original layout */
    .tuvan-page,
    .tuvan-detail,
    .article-detail,
    .technical-consultation-page {
        max-width: 1135px;
        padding: 20px;
        overflow-x: visible;
    }
    
    /* Desktop grids - maintain original 3-column layout */
    .tuvan-grid,
    .articles-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 25px;
    }
    
    /* Desktop headers - maintain original sizes */
    .tuvan-header h1 {
        font-size: 2.8rem;
    }
    
    .tuvan-header p,
    .page-header p {
        font-size: 1.2rem;
    }
    
    /* Desktop images - maintain original behavior */
    .tuvan-image,
    .article-image {
        height: 220px;
    }
    
    /* Desktop content - maintain original padding */
    .tuvan-content,
    .article-content {
        padding: 25px;
    }
}

/* ===== TABLET BREAKPOINT (769px - 968px) ===== */
@media (min-width: 769px) and (max-width: 968px) {
    
    /* Tablet uses 2-column grid like original design */
    .tuvan-grid,
    .articles-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
    }
}

/* ===== FORCE OVERRIDES FOR STUBBORN ELEMENTS ===== */

/* Only target specific problematic elements, don't affect everything */
html body img[src*="logo.png"] {
    /* Logo fix with highest specificity - mobile only */
}

@media (max-width: 768px) {
    html body img[src*="logo.png"] {
        max-width: 60px !important;
        max-height: 60px !important;
        width: auto !important;
        height: auto !important;
        margin-top: -5px !important;
        vertical-align: top !important;
    }
    
    /* Tuvan content images with highest specificity - mobile only */
    html body .tuvan-detail-content img,
    html body .tuvan-detail img,
    html body .article-detail-content img,
    html body #noidungtrong img {
        max-width: 100% !important;
        width: auto !important;
        height: auto !important;
    }
}

/* ===== NO GENERIC OVERRIDES ===== */
/* Don't use generic * selectors that affect everything */
/* Don't override global box-sizing unless necessary */
/* Don't force max-width on all images globally */
