/* =========================================================
   HEADER SOCIAL + VIDEO MOBILE/TABLET V10.16
   - Áp dụng mobile + tablet < 1200px.
   - Desktop >= 1200px giữ nguyên.
   - Đưa nhóm button .header .social xuống BÊN DƯỚI banner.
   - Xếp 3 cột / hàng; nếu số button không đủ 3 ở hàng cuối
     thì tự căn giữa nhờ flex + justify-content:center.
   - Không tác động nhóm .social-footer khác trong index_tpl.php.
   - Bật video banner trên mobile + tablet bằng bản MP4 tối ưu riêng (~0.9 MB).
   - Ảnh fallback WebP giữ lại để hiển thị nhẹ trong lúc video chưa chạy.
   ========================================================= */

@media (max-width: 1199.98px) {
    /*
     * responsive.css đang dùng banner mobile/tablet bằng background của .header
     * với chiều cao 450px. Ta giữ nguyên phần banner 450px ở phía trên,
     * sau đó cho container social chạy theo flow ngay bên dưới.
     */
    .header {
        position: relative !important;
        height: auto !important;
        min-height: 0 !important;
        padding-top: 450px !important;
        box-sizing: border-box !important;

        /* Tách banner khỏi vùng button để button thật sự nằm bên dưới. */
        background: none !important;
    }

    .header::before {
        content: "";
        position: absolute;
        z-index: 0;
        top: 0;
        left: 0;
        right: 0;
        height: 450px;

        background: url(../images/header-mobile-fallback.webp) no-repeat top center;
        background-size: cover;
        pointer-events: none;
    }

    /* Chỉ container trực tiếp của header chứa các button phía trên. */
    .header > .container {
        position: relative !important;
        z-index: 30 !important;

        width: 100% !important;
        max-width: 100% !important;

        margin: 0 auto !important;
        padding: 8px 7px 10px !important;
        box-sizing: border-box !important;
    }

    /*
     * Dùng flex thay vì grid để:
     * - luôn đúng 3 button / hàng;
     * - hàng cuối có 1 hoặc 2 button vẫn tự căn giữa đẹp.
     */
    .header .social.social-footer {
        width: 100% !important;
        max-width: 720px !important;

        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: center !important;

        gap: 6px !important;
        margin: 0 auto !important;
        padding: 0 !important;
    }

    .header .social.social-footer > li {
        width: calc((100% - 12px) / 3) !important;
        max-width: calc((100% - 12px) / 3) !important;
        min-width: 0 !important;
        flex: 0 0 calc((100% - 12px) / 3) !important;

        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    .header .social.social-footer > li > a {
        position: relative !important;
        display: block !important;
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        line-height: 0 !important;
        overflow: hidden !important;
    }

    .header .social.social-footer > li > a > img {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
        aspect-ratio: 320 / 100 !important;
        object-fit: contain !important;
    }

    /* Chữ nằm đúng trong ảnh button và không bị xuống dòng. */
    .header .social.social-footer li .name {
        top: 50% !important;
        left: 39% !important;
        right: 3% !important;
        width: auto !important;

        transform: translateY(-50%) !important;

        font-size: clamp(10px, 2.7vw, 16px) !important;
        line-height: 1 !important;
        text-align: center !important;
        white-space: nowrap !important;

        margin: 0 !important;
        padding: 0 !important;
        pointer-events: none !important;
    }

    /*
     * VIDEO BANNER MOBILE + TABLET
     * responsive.css ẩn .header .video ở <=1199px; override tại đây cho cả mobile + tablet.
     * Video nằm tuyệt đối trong đúng vùng banner 450px, button vẫn ở flow phía dưới.
     * ::before bên dưới đóng vai trò ảnh fallback trong lúc video tải.
     */
    .header > .video {
        display: block !important;
        position: absolute !important;
        z-index: 1 !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: none !important;
        height: 450px !important;
        overflow: hidden !important;
        transform: none !important;
        pointer-events: none !important;
        background: transparent !important;
    }

    .header > .video > video {
        display: block !important;
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        object-fit: cover !important;
        object-position: center center !important;
    }

    /* Trên màn cảm ứng không scale button sau khi chạm. */
    .header .social.social-footer li > a:hover {
        transform: none !important;
    }
}


/* Tablet: vẫn 3 cột x 2 hàng như mobile nhưng giữ cụm nút gọn, cân giữa. */
@media (min-width: 768px) and (max-width: 1199.98px) {
    .header > .container {
        padding-top: 10px !important;
        padding-bottom: 12px !important;
    }

    .header .social.social-footer {
        max-width: 820px !important;
        gap: 8px !important;
    }

    .header .social.social-footer > li {
        width: calc((100% - 16px) / 3) !important;
        max-width: calc((100% - 16px) / 3) !important;
        flex-basis: calc((100% - 16px) / 3) !important;
    }

    .header .social.social-footer li .name {
        font-size: clamp(14px, 1.8vw, 18px) !important;
    }
}

@media (max-width: 420px) {
    .header > .container {
        padding-left: 5px !important;
        padding-right: 5px !important;
    }

    .header .social.social-footer {
        gap: 4px !important;
    }

    .header .social.social-footer > li {
        width: calc((100% - 8px) / 3) !important;
        max-width: calc((100% - 8px) / 3) !important;
        flex-basis: calc((100% - 8px) / 3) !important;
    }

    .header .social.social-footer li .name {
        left: 38% !important;
        right: 2% !important;
        font-size: clamp(9px, 2.65vw, 12px) !important;
    }
}
