/* ==========================================================================
   RESPONSIVE MOBILE & TABLET (GOM TỪ TOÀN BỘ FILE GỐC)
   ========================================================================== */

/* ==========================================================================
   1. TỐI ƯU CƠ BẢN & ẨN PHẦN TỬ (< 991px)
   ========================================================================== */
@media (max-width: 991px) { 
    .wpshare247-hide-on-mobile { display: none !important; } 
    .wpshare247-header__main .wpshare247-container { flex-wrap: wrap; } 
    .wpshare247-header__search { order: 3; min-width: 100%; margin-top: 15px; } 
    .wpshare247-mobile-menu-btn { display: block; } 
    
    /* Lưới chung */
    .wpshare247-contact-grid { grid-template-columns: 1fr !important; gap: 30px !important; }
    .wpshare247-footer-grid { grid-template-columns: 1fr 1fr; } 
    .wpshare247-core-bento-layout { grid-template-columns: 1fr; }
    .wpshare247-core-large { min-height: 350px; }
    
    .wpshare247-cart-layout-modern { grid-template-columns: 1fr; }
    
    /* Vô hiệu hóa WOW.js trên mobile để tránh kẹt tàng hình */
    .wow { visibility: visible !important; animation: none !important; opacity: 1 !important; transform: none !important; }
    html, body { height: auto !important; min-height: 100vh; }

    /* ======================================================================
       TỐI ƯU CỠ CHỮ TIÊU ĐỀ TRÊN TABLET (< 991px)
       ====================================================================== */
    .wpshare247-anim-title {
        font-size: 1.85rem !important;
        line-height: 1.35 !important;
        margin-bottom: 12px !important;
    }
    .wpshare247-anim-desc {
        font-size: 1rem !important;
        line-height: 1.5 !important;
        margin-bottom: 20px !important;
    }
    .wpshare247-section-header h2,
    .wpshare247-section h2,
    .tbay-feature-title,
    .tbay-cta-title,
    .wpshare247-banner-content h2,
    h1.wpshare247-page-title,
    h1.entry-title,
    h1.product_title,
    .woocommerce-products-header__title {
        font-size: 1.65rem !important;
        line-height: 1.35 !important;
        letter-spacing: normal !important;
    }
    .wpshare247-section-header p {
        font-size: 0.95rem !important;
        line-height: 1.5 !important;
    }
    .tbay-contact-card-title,
    .tbay-policy-clean-card h3,
    .wpshare247-lively-card h3,
    .tbay-core-floating-content h3,
    .wpshare247-core-card-item h3,
    .wpshare247-process-step h3 {
        font-size: 1.15rem !important;
        line-height: 1.4 !important;
    }
}

@media (max-width: 576px) { 
    .wpshare247-footer-grid { grid-template-columns: 1fr; } 
}

/* ==========================================================================
   2. CHỈNH SỬA BỐ CỤC & TIÊU ĐỀ MOBILE (< 768px)
   ========================================================================== */
@media (max-width: 768px) { 
    /* Chữ & Banner */
    .wpshare247-anim-title { 
        font-size: 1.35rem !important; 
        line-height: 1.3 !important; 
        margin-bottom: 10px !important;
        word-break: break-word !important;
    } 
    .wpshare247-anim-desc,
    .wpshare247-slide-content p.wpshare247-anim-desc { 
        font-size: 0.9rem !important; 
        line-height: 1.45 !important;
        margin-bottom: 15px !important;
    }
    .wpshare247-banner-wrap { flex-direction: column !important; text-align: center !important; padding: 30px 15px !important; gap: 15px !important;} 
    .wpshare247-banner-content h2 { font-size: 1.3rem !important; line-height: 1.35 !important;}
    
    /* Layout & Section */
    .wpshare247-trust-bar { display: none; } 
    .wpshare247-process-timeline { flex-direction: column !important; gap: 25px !important;} 
    .wpshare247-process-timeline::before { display: none; } 
    .wpshare247-stats-grid { grid-template-columns: 1fr 1fr !important; gap: 15px !important;} 
    .wpshare247-auth-panel { padding: 25px; }
    .wpshare247-container { padding: 0 15px !important; }
    .wpshare247-section { padding: 30px 0 !important; }
    
    /* Tiêu đề khối & Trang con (< 768px) */
    .wpshare247-section-header h2,
    .wpshare247-section h2,
    .tbay-feature-title,
    .tbay-cta-title,
    h1.wpshare247-page-title,
    h1.entry-title,
    h1.product_title,
    .woocommerce-products-header__title { 
        font-size: 1.25rem !important; 
        line-height: 1.35 !important; 
        padding: 0 !important; 
        margin-bottom: 10px !important;
        word-break: break-word !important;
    }
    .wpshare247-section-header p,
    .tbay-feature-desc,
    .tbay-cta-desc {
        font-size: 0.88rem !important;
        line-height: 1.5 !important;
        margin-bottom: 15px !important;
    }

    /* Tiêu đề thẻ con cấp 3 (Cards h3) */
    .tbay-contact-card-title,
    .tbay-policy-clean-card h3,
    .wpshare247-lively-card h3,
    .tbay-core-floating-content h3,
    .wpshare247-core-card-item h3,
    .wpshare247-process-step h3 {
        font-size: 1.05rem !important;
        line-height: 1.35 !important;
        margin-bottom: 8px !important;
    }

    .wpshare247-faq-question {
        font-size: 0.95rem !important;
        line-height: 1.4 !important;
        padding: 12px 15px !important;
    }
    .wpshare247-faq-answer,
    .wpshare247-faq-answer p {
        font-size: 0.88rem !important;
        line-height: 1.5 !important;
    }

    .wpshare247-post-title,
    .wpshare247-post-title a {
        font-size: 1rem !important;
        line-height: 1.35 !important;
    }
    
    /* Modal & FAB */
    .wpshare247-modal-content { grid-template-columns: 1fr; max-height: 90vh; overflow-y: auto; padding: 20px; }
    .wpshare247-modal-modern { grid-template-columns: 1fr !important; gap: 20px !important; padding: 20px !important;}
    .wpshare247-fab-container { bottom: 10px !important; right: 10px !important; gap: 10px !important; transform: scale(0.7) !important; transform-origin: bottom right !important; }
    
    /* Ép thẻ SP 2 cột */
    .wpshare247-products { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
    .wpshare247-product-img-wrap { padding: 10px !important; }
    .wpshare247-ribbon { padding: 2px 6px !important; font-size: 0.65rem !important; top: 8px !important; left: 8px !important; }
    .wpshare247-product-info { padding: 0 10px 15px !important; }
    .woocommerce-loop-product__title { font-size: 0.85rem !important; height: 38px !important; overflow: hidden !important; display: -webkit-box !important; -webkit-line-clamp: 2 !important; -webkit-box-orient: vertical !important; margin-bottom: 5px !important; }
    .wpshare247-price-new { font-size: 1.05rem !important; }
    .wpshare247-price-old { font-size: 0.8rem !important; }
    .wpshare247-product-sku { font-size: 0.7rem !important; margin-bottom: 8px !important;}
    .wpshare247-product-actions { grid-template-columns: 1fr !important; gap: 5px !important; }
    .wpshare247-btn-action { padding: 8px 5px !important; font-size: 0.75rem !important; }
    
    /* Chứng nhận */
    .wpshare247-cert-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
    .wpshare247-cert-card { padding: 15px !important; }
    .wpshare247-cert-card img { width: 45px !important; height: 45px !important; margin-bottom: 10px !important;}
    .wpshare247-cert-card h4 { font-size: 0.9rem !important; }

    /* Chống tràn viền toàn diện */
    body, html { overflow-x: hidden !important; max-width: 100vw !important; }
    .wpshare247-bg-style--white > .wpshare247-container > div[style*="grid-template-columns"] { grid-template-columns: 1fr !important; gap: 30px !important; }
    .wpshare247-stat-item { padding: 15px 10px !important; }
    .wpshare247-stat-num { font-size: 1.8rem !important; }
    .wpshare247-stat-text { font-size: 0.8rem !important; }
    
    /* Giao diện Giỏ hàng Mobile */
    .wpshare247-cart-item-modern { flex-wrap: wrap; padding: 15px; gap: 15px; }
    .wpshare247-cart-item-img { width: 75px; height: 75px; }
    .wpshare247-cart-item-info, .wpshare247-cart-item-details { min-width: 150px; }
    .wpshare247-cart-item-title { font-size: 1rem; }
    .wpshare247-cart-item-name { font-size: 0.95rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .wpshare247-cart-item-remove { position: absolute; top: 10px; right: 10px; padding: 5px; }
    .wpshare247-cart-header-row { flex-direction: column; align-items: flex-start; gap: 15px; }
    .wpshare247-cart-page-title { font-size: 1.8rem; }
    .wpshare247-btn-clear-cart { width: 100%; }
    .wpshare247-cart-item-row { flex-wrap: wrap; padding: 15px; gap: 12px; }
    .wpshare247-cart-item-actions { width: 100%; justify-content: space-between; margin-top: 5px; padding-top: 15px; border-top: 1px dashed #e2e8f0; }
}

/* ==========================================================================
   3. MENU HAMBURGER & DROPDOWN (TRÁI SANG) DÀNH RIÊNG CHO <= 991px
   ========================================================================== */
@media (max-width: 991px) {
    /* Đánh bại class hide-on-mobile cũ */
    .wpshare247-header__nav-bar { display: block !important; }

    /* Cấu trúc trượt từ trái sang */
    .wpshare247-header__nav-bar {
        position: fixed !important; top: 0 !important; left: -100% !important; width: 85vw !important; max-width: 320px !important; 
        height: 100vh !important; background: #ffffff !important; box-shadow: 5px 0 25px rgba(0,0,0,0.2) !important; z-index: 10000 !important;
        transition: left 0.4s cubic-bezier(0.165, 0.84, 0.44, 1) !important; overflow-y: auto !important; padding-top: 0 !important;
    }
    .wpshare247-header__nav-bar.mobile-active { left: 0 !important; }
    .wpshare247-main-nav { display: flex !important; flex-direction: column !important; width: 100% !important; justify-content: flex-start !important; }
    .wpshare247-main-nav > li { text-align: left !important; border-bottom: 1px solid #f1f5f9 !important; width: 100% !important;}
    .wpshare247-main-nav > li > a { padding: 16px 24px !important; display: flex !important; justify-content: space-between !important; font-size: 1rem !important; color: var(--wpshare247-text-main) !important; font-weight: 700 !important; }
    
    /* Chống kẹt và hiệu ứng Sub-menu */
    .wpshare247-main-nav .sub-menu { position: static !important; box-shadow: none !important; border: none !important; background: #f8fafc !important; padding-left: 0 !important; display: none !important; visibility: hidden !important; opacity: 0 !important; }
    ul.wpshare247-main-nav > li.menu-item-has-children > ul.sub-menu { display: none !important; visibility: hidden !important; opacity: 0 !important; }
    .wpshare247-main-nav .menu-item-has-children.active > ul.sub-menu,
    ul.wpshare247-main-nav > li.menu-item-has-children.active > ul.sub-menu { display: block !important; visibility: visible !important; opacity: 1 !important; animation: fadeInMenu 0.3s ease forwards; }
    .wpshare247-main-nav .sub-menu li a { padding: 14px 24px 14px 40px !important; border-bottom: 1px solid #e2e8f0 !important; font-size: 0.9rem !important; font-weight: 500 !important; color: var(--wpshare247-text-muted) !important; }

    /* Cấu trúc Header Mobile: Nút 3 gạch Trái - Logo Giữa - Tài khoản & Giỏ hàng Phải */
    .wpshare247-header__main .wpshare247-container {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 10px 15px !important;
        position: relative !important;
        gap: 0 !important;
    }
    .wpshare247-mobile-menu-btn {
        order: 1 !important;
        position: static !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 38px !important;
        height: 38px !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 8px !important;
        background: #ffffff !important;
        color: var(--wpshare247-color-primary-dark) !important;
        margin: 0 !important;
        font-size: 20px !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
    }
    .wpshare247-header__logo {
        order: 2 !important;
        margin: 0 auto !important;
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        position: static !important;
        flex-shrink: 0 !important;
    }
    .wpshare247-header__logo img {
        width: 28px !important;
        height: 28px !important;
    }
    .wpshare247-header__logo span {
        font-size: 1.7rem !important;
    }
    .wpshare247-header__actions {
        order: 3 !important;
        position: static !important;
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        margin: 0 !important;
        flex-shrink: 0 !important;
    }
    .wpshare247-header__actions .wpshare247-action-item {
        position: relative !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 36px !important;
        color: var(--wpshare247-text-main) !important;
        text-decoration: none !important;
        padding: 2px !important;
        font-size: 0.65rem !important;
        font-weight: 700 !important;
        line-height: 1 !important;
    }
    .wpshare247-header__actions .wpshare247-action-item svg {
        width: 22px !important;
        height: 22px !important;
        margin-bottom: 3px !important;
    }
    .wpshare247-header__actions .wpshare247-action-badge {
        position: absolute !important;
        top: -5px !important;
        right: -3px !important;
        background: var(--wpshare247-color-accent) !important;
        color: #ffffff !important;
        font-size: 10px !important;
        padding: 1px 5px !important;
        border-radius: 999px !important;
        border: 2px solid #ffffff !important;
        line-height: 1.2 !important;
    }
    .wpshare247-header__search {
        order: 4 !important;
        width: 100% !important;
        min-width: 100% !important;
        margin-top: 10px !important;
    }

    /* Nút đóng Menu (X) chuẩn Nệm Thuần Việt */
    .wpshare247-mobile-menu-header { display: flex !important; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid #e2e8f0; margin-bottom: 15px; background: #ffffff; }
    .wpshare247-mobile-close-btn { background: #ffffff; border: 1px solid #cbd5e1; border-radius: 8px; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; color: var(--wpshare247-text-main); cursor: pointer; transition: 0.3s; }
    .wpshare247-mobile-close-btn:hover { border-color: #ef4444; color: #ef4444; }
}

@keyframes fadeInMenu { 
    from { opacity: 0; transform: translateY(-10px); } 
    to { opacity: 1; transform: translateY(0); } 
}

/* ==========================================================================
   4. ĐIỆN THOẠI MÀN HÌNH NHỎ (< 480px)
   ========================================================================== */
@media (max-width: 480px) {
    .wpshare247-anim-title {
        font-size: 1.2rem !important;
        line-height: 1.25 !important;
    }
    .wpshare247-anim-desc {
        font-size: 0.85rem !important;
    }

    .wpshare247-section-header h2,
    .wpshare247-section h2,
    .tbay-feature-title,
    .tbay-cta-title,
    h1.product_title {
        font-size: 1.15rem !important;
        line-height: 1.3 !important;
    }

    .tbay-contact-card-title,
    .tbay-policy-clean-card h3,
    .wpshare247-lively-card h3 {
        font-size: 0.98rem !important;
    }
}
/* ==========================================================================
   5. CHUẨN HÓA GIAO DIỆN DI ĐỘNG & BẪY PHẦN CỨNG SAFARI IOS (COMMERCIAL HARDENING)
   ========================================================================== */

/* 5.1. Chống lỗi Auto-Zoom trên Safari iOS: Bắt buộc font-size >= 16px trên di động (BUG-UI-001) */
@media screen and (max-width: 991px) {
    input[type="text"],
    input[type="tel"],
    input[type="email"],
    input[type="number"],
    input[type="search"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* 5.2. Chống lỗi 100vh trên Drawer Navigation của iPhone (Dùng 100dvh + Safe Area) */
@media screen and (max-width: 991px) {
    .wpshare247-header__nav-bar {
        height: 100vh !important;
        height: 100dvh !important;
        padding-bottom: calc(25px + env(safe-area-inset-bottom)) !important;
        box-sizing: border-box !important;
    }
}

/* 5.3. Tránh đè lên thanh Home Indicator trên iPhone tràn viền */
.wpshare247-fab-container,
.tbay-sticky-cta,
.wpshare247-bottom-nav {
    bottom: calc(15px + env(safe-area-inset-bottom)) !important;
}

/* 5.4. Công thái học: Kích thước vùng bấm tối thiểu 44px x 44px (Apple HIG & WCAG 2.1 AA) */
.wpshare247-qty-control button,
.wpshare247-modal-close,
.wpshare247-mobile-close-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* ẨN TRIỆT ĐỂ NÚT HAMBURGER TRÊN DESKTOP/MÀN HÌNH MÁY TÍNH (>= 992px) */
@media (min-width: 992px) {
    .wpshare247-mobile-menu-btn {
        display: none !important;
    }
}

/* 5.5. Chống tràn bảng thông số kỹ thuật trên màn hình hẹp 360px (BUG-UI-003) */
.tbay-table-responsive,
.tbay-product-enterprise-specs {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    background: linear-gradient(to right, white 30%, rgba(255,255,255,0)),
                linear-gradient(to right, rgba(255,255,255,0), white 70%) 100% 0,
                radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.15), rgba(0,0,0,0)),
                radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.15), rgba(0,0,0,0)) 100% 0;
    background-repeat: no-repeat;
    background-color: #fff;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
}

.tbay-product-enterprise-specs table,
.woocommerce-product-attributes.shop_attributes {
    min-width: 300px;
    width: 100% !important;
    word-break: break-word;
}

/* 5.6. Phục hồi đường viền Focus chuẩn tiếp cận (WCAG 2.1 AA) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--wpshare247-color-primary, #0284c7) !important;
    outline-offset: 2px !important;
}

/* 5.7. Hiệu ứng sóng rung nút nổi (Pulse Wave Animation) */
.tbay-fab-pulse {
    position: relative;
}
.tbay-fab-pulse::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: inherit;
    opacity: 0.7;
    animation: tbayPulseWave 2s infinite ease-out;
    z-index: -1;
    pointer-events: none;
}
@keyframes tbayPulseWave {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
    }
    70% {
        transform: translate(-50%, -50%) scale(1.6);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.8);
        opacity: 0;
    }
}
