/* ==========================================================================
   PERFORMANCE OPTIMIZATION STYLESHEET - TỐI ƯU HIỆU NĂNG ĐA NỀN TẢNG
   ==========================================================================
   MỤC LỤC / TABLE OF CONTENTS:
   01. ANIMATION THROTTLING     - Tắt animation tiêu tốn CPU/pin trên màn hình nhỏ
   02. HARDWARE ACCELERATION    - Kích hoạt GPU (will-change, transform: translateZ)
   03. CONTENT VISIBILITY       - Tối ưu tải ngầm các thành phần nằm ngoài viewport
   04. FONT RENDERING SMOOTHING - Chống răng cưa font trên macOS, iOS và Windows
   05. TOUCH INTERACTION TWEAKS - Tối ưu phản hồi cảm ứng trên thiết bị di động
   06. MEMORY & PAINT SAVINGS   - Giảm thiểu hiện tượng repaint / reflow liên tục
   ========================================================================== */

/* =========================================================
   1. GIẢM ANIMATION TRÊN THIẾT BỊ YẾU
   ========================================================= */

/* ⭐ Tắt animation nặng trên mobile + tablet */
@media (max-width: 1024px) {
    /* Tắt animation nền body */
    body,
    body::before,
    body::after {
        animation: none !important;
    }
    
    /* Tắt animation hero + contact hero */
    .hero,
    .contact-hero,
    .hero-slideshow,
    .hero-slideshow::after,
    .contact-hero::before,
    .contact-hero::after,
    .contact-hero-icon {
        animation: none !important;
    }
    
    /* Tắt animation top-nav + footer */
    .top-nav::after,
    .footer::before {
        animation: none !important;
        background-size: 100% 100% !important;
    }
    
    /* Tắt animation nút + icon */
    .top-nav .hotline-box .icon,
    .footer .hotline-box-footer .phone-icon,
    .hero .badge-top,
    .section-title h2,
    .welcome-banner::after,
    .welcome-line-2,
    .contact-hero-icon {
        animation: none !important;
    }
    
    /* Tắt animation card + pkg */
    .pkg-wrap::before,
    .pkg-ribbon-hot,
    .pkg-ribbon-featured,
    .btn-pkg::before,
    .addr-toggle-btn {
        animation: none !important;
    }
    
    /* Tắt backdrop-filter — tốn GPU */
    .top-nav,
    .user-avatar,
    .mobile-menu,
    .hero .badge-top,
    .hero .badges span,
    .btn-hero-secondary,
    .hero-nav,
    .hero-dots,
    .contact-hero .container {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
    
    /* Tắt background-attachment: fixed */
    body,
    html {
        background-attachment: scroll !important;
    }
    
    /* ⭐ Giảm shadow nặng */
    .hero,
    .feature,
    .device,
    .pkg-wrap,
    .pkg,
    .contact-wrapper,
    .contact-info-card,
    .footer,
    .top-nav,
    .user-dropdown,
    .ai-chat-window {
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08) !important;
    }

    .hero-slideshow {
        box-shadow:
            0 0 24px rgba(243, 112, 33, 0.5),
            0 0 50px rgba(255, 140, 66, 0.32) !important;
    }
    
    /* ⭐ Tắt will-change — giải phóng bộ nhớ GPU */
    .pkg-wrap::before,
    .hero-nav {
        will-change: auto !important;
    }
    
    /* ⭐ Tắt filter blur nặng */
    body::before,
    body::after {
        filter: none !important;
    }
}

/* =========================================================
   2. THIẾT BỊ YẾU (RAM thấp) — TẮT NHIỀU HƠN
   ========================================================= */

@media (max-width: 640px) {
    /* ⭐ Tắt các hoạt ảnh trang trí nặng tiêu tốn GPU/CPU */
    .hero,
    .hero::before,
    .hero::after,
    .hero-slideshow::after,
    .contact-hero,
    .contact-hero::before,
    .contact-hero::after,
    .pkg-wrap::before,
    .section-title h2,
    .th-draw,
    .th-main {
        animation: none !important;
    }

    /* ⭐ Hiển thị rõ chữ SVG tiêu đề chính khi tắt animation trên mobile */
    .th-main {
        opacity: 1 !important;
    }

    .th-draw {
        stroke-dashoffset: 0 !important;
        opacity: 0.28 !important;
    }

    /* Giữ transition nhẹ nhàng cho tương tác mượt mà */
    button,
    a,
    input,
    select,
    textarea,
    .hamburger-btn,
    .hamburger-btn span,
    .mobile-menu,
    .mobile-menu-overlay,
    .user-dropdown,
    .ai-chat-window,
    .btn-pkg,
    .btn-hero-primary,
    .btn-hero-secondary {
        transition-duration: 0.25s !important;
    }
    
    /* ⭐ Giảm số sao trong hero-stars */
    .hero-stars .stars-3 {
        display: none !important;
    }
    
    .hero-stars .m2,
    .hero-stars .m3 {
        display: none !important;
    }
    
    /* ⭐ Giảm số sao trong midnight-sky */
    .midnight-sky .stars-3 {
        display: none !important;
    }
    
    .midnight-sky .m2,
    .midnight-sky .m3 {
        display: none !important;
    }
    
    /* ⭐ Tắt sao lấp lánh phức tạp */
    .hero-stars .stars-1,
    .hero-stars .stars-2,
    .midnight-sky .stars-1,
    .midnight-sky .stars-2 {
        animation: none !important;
        opacity: 0.8 !important;
    }
    
    /* ⭐ Giảm blur và shadow */
    .ai-chat-button,
    .theme-toggle-btn,
    .ai-chat-window,
    .hero-nav,
    .contact-info-card {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    }
    
    /* ⭐ Tắt hiệu ứng hover phức tạp (mobile không cần) */
    .pkg-wrap:hover,
    .feature:hover,
    .device:hover,
    .contact-info-card:hover,
    .user-avatar:hover,
    .btn-pkg:hover,
    .btn-hero-primary:hover,
    .btn-hero-secondary:hover {
        transform: none !important;
    }
    
    /* ⭐ Tắt viền xoay pkg — chỉ hiện viền tĩnh */
    .pkg-wrap::before {
        animation: none !important;
        background: linear-gradient(135deg, #f37021 0%, #ffb26b 50%, #f37021 100%) !important;
        opacity: 0.3 !important;
    }
    
    /* ⭐ Tắt ripple effect animation */
    @keyframes rippleAnim {
        to { width: 200px; height: 200px; opacity: 0; }
    }
    
    /* ⭐ Giảm gradient phức tạp */
    .hero {
        background: linear-gradient(180deg, #1a4b8c 0%, #0f3266 100%) !important;
    }
    
    body.dark-mode .hero,
    body.dark-mode .contact-hero {
        background: linear-gradient(180deg, #0b1a3a 0%, #0f2350 100%) !important;
    }
    
    /* ⭐ Giữ ánh sáng cam nhẹ cho khung slideshow trên mobile */
    .hero-slideshow {
        box-shadow:
            0 0 18px rgba(243, 112, 33, 0.45),
            0 6px 20px rgba(243, 112, 33, 0.25) !important;
    }
    
    /* ⭐ Tắt text-shadow nặng */
    .welcome-line-2,
    .hero h1 .highlight,
    .pkg .price {
        text-shadow: none !important;
    }
    
    /* ⭐ Đơn giản hóa gradient text */
    .section-title h2,
    .welcome-line-2 {
        background: none !important;
        -webkit-text-fill-color: #d95810 !important;
        color: #d95810 !important;
    }
    
    body.dark-mode .section-title h2 {
        color: #f3f4f6 !important;
        -webkit-text-fill-color: #f3f4f6 !important;
    }
}

/* =========================================================
   3. TÔN TRỌNG CÀI ĐẶT USER — REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .hero,
    .contact-hero,
    body,
    body::before,
    body::after {
        animation: none !important;
    }

    .th-main {
        opacity: 1 !important;
    }

    .th-draw {
        stroke-dashoffset: 0 !important;
        opacity: 0.28 !important;
    }
}

/* =========================================================
   4. TỐI ƯU CHO iOS — SMOOTH SCROLLING
   ========================================================= */

@supports (-webkit-touch-callout: none) {
    /* iOS-specific */
    body,
    .hero,
    .contact-hero {
        -webkit-overflow-scrolling: touch;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* iOS Safari — fix 100vh issue */
    .mobile-menu,
    .ai-chat-window {
        max-height: 90vh;
        max-height: 90dvh;
    }
    
    /* iOS — giảm animation để tiết kiệm pin */
    body,
    .hero,
    .contact-hero {
        animation: none !important;
    }
    
    /* iOS — tắt parallax */
    body {
        background-attachment: scroll !important;
    }
}

/* =========================================================
   5. TỐI ƯU CHO ANDROID — TẮT HIỆU ỨNG NẶNG (CHỈ TRÊN MOBILE/TABLET)
   ========================================================= */

@media (max-width: 1024px) {
    @supports (-webkit-appearance: none) and (not (-webkit-touch-callout: none)) {
        /* Android-specific */
        html {
            -webkit-tap-highlight-color: transparent;
        }
        
        /* Android — tắt backdrop-filter cho thanh điều hướng (giữ nguyên màu gốc cho ai-chat-window & hero-nav) */
        .top-nav,
        .mobile-menu {
            backdrop-filter: none !important;
            -webkit-backdrop-filter: none !important;
            background: rgba(10, 31, 68, 0.96) !important;
        }

        .user-avatar,
        .ai-chat-window,
        .hero-dots,
        .hero-nav {
            backdrop-filter: none !important;
            -webkit-backdrop-filter: none !important;
        }
        
        /* Android — fix scroll lag */
        body {
            overscroll-behavior-y: contain;
        }
        
        /* Android — tắt transform 3D phức tạp */
        .pkg-wrap,
        .pkg {
            transform: translateZ(0);
            backface-visibility: hidden;
        }
        
        /* Android — tắt animation pulse trên màn hình nhỏ */
        .ai-chat-button,
        .contact-hero-icon,
        .footer .hotline-box-footer .phone-icon {
            animation: none !important;
        }
    }
}

/* =========================================================
   6. TỐI ƯU CHO macOS / WINDOWS — GIỮ HIỆU ỨNG ĐẸP
   ========================================================= */

@media (min-width: 1025px) {
    /* Desktop — giữ nguyên tất cả hiệu ứng đẹp */
    
    /* Tối ưu rendering */
    html {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
    
    /* GPU acceleration cho element chuyển động */
    .hero-slideshow,
    .hero-slide,
    .pkg-wrap,
    .pkg-wrap::before,
    .hero-nav,
    .dot-slide,
    .ai-chat-button {
        transform: translateZ(0);
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
    
    /* Will-change cho element animate liên tục */
    .pkg-wrap::before,
    .hero-slideshow::after,
    .hero-stars .meteor,
    .midnight-sky .meteor {
        will-change: transform, opacity;
    }
    
    /* Tắt will-change cho element ít animate */
    .pkg-ribbon-hot,
    .pkg-ribbon-featured,
    .hero-nav {
        will-change: auto;
    }
}

/* =========================================================
   7. TỐI ƯU CHUNG — CHO TẤT CẢ THIẾT BỊ
   ========================================================= */

/* ⭐ Tắt animation khi tab ẩn — tiết kiệm pin */
body:not(:hover) .pkg-wrap::before,
body:not(:hover) .hero-slideshow::after {
    animation-play-state: paused;
}

/* ⭐ Fix layout shift — tránh giật khi load font */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* ⭐ Tối ưu scroll cho mọi thiết bị */
html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
}

@media (max-width: 640px) {
    html {
        scroll-padding-top: 60px;
    }
}

/* ⭐ Tối ưu render — chỉ áp dụng content-visibility trên desktop để tránh giật cuộn mobile */
@media (min-width: 1025px) {
    .features,
    .devices,
    .contact-section,
    .footer {
        content-visibility: auto;
        contain-intrinsic-size: auto 600px;
    }
}

@media (max-width: 1024px) {
    .features,
    .devices,
    .contact-section,
    .footer {
        content-visibility: visible !important;
    }
}

/* ⭐ Ngăn iOS Safari tự động phóng to màn hình khi bấm vào ô nhập liệu */
@media (max-width: 768px) {
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Chống tràn ngang tuyệt đối trên mọi thiết bị di động */
    html,
    body {
        overflow-x: clip !important;
        max-width: 100vw !important;
        position: relative;
    }

    /* Tối ưu phản hồi chạm tức thì, không bị trễ 300ms */
    a,
    button,
    input,
    select,
    textarea,
    .hamburger-btn,
    .theme-toggle-btn,
    .ai-chat-button,
    .dot-slide {
        touch-action: manipulation;
    }

    /* ⭐ Đảm bảo toàn bộ nội dung (tiêu đề, thẻ gói, Mesh, thiết bị, form) hiển thị ngay lập tức trên mobile, không bị trắng trang */
    .reveal {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
}

/* ⭐ Giữ tỷ lệ tự nhiên của ảnh trong khung cố định */
.device .img-wrap img,
.hero-slide {
    aspect-ratio: auto;
}

/* ⭐ Tắt animation khi user scroll nhanh */
@media (prefers-reduced-motion: no-preference) {
    .reveal {
        will-change: opacity, transform;
    }
    
    .reveal.active {
        will-change: auto;
    }
}

/* =========================================================
   8. FALLBACK — NẾU TRÌNH DUYỆT KHÔNG HỖ TRỢ
   ========================================================= */

/* Fallback cho trình duyệt cũ không hỗ trợ aspect-ratio */
@supports not (aspect-ratio: 1) {
    .device .img-wrap {
        padding-top: 75%;
        position: relative;
    }
    
    .device .img-wrap img {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
}

/* Fallback cho trình duyệt cũ không hỗ trợ content-visibility */
@supports not (content-visibility: auto) {
    .features,
    .devices,
    .contact-section {
        content-visibility: visible;
    }
}

/* =========================================================
   9. AUTH PAGES (LOGIN, REGISTER, FORGOT, RESET) TỐI ƯU 60FPS
   ========================================================= */
.login-body {
    contain: paint;
    overscroll-behavior-y: contain;
}

.login-bg,
.login-blob,
.glass-input-wrap,
.glass-btn,
.glass-btn-primary {
    transform: translateZ(0);
    backface-visibility: hidden;
}

@media (max-width: 768px) {
    .login-modal-overlay {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: rgba(10, 15, 30, 0.88) !important;
    }
}