/* =====================================================================
   QUANLYSO.VN – RESPONSIVE & MOBILE FIXES  (v2.0.0 – 29/11/2026)
   Nạp SAU CÙNG (cuối <body>) để chuẩn hoá hiển thị trên mọi thiết bị.
   Không sửa các file CSS cũ; mọi điều chỉnh nằm tại đây.
   ===================================================================== */

/* ---------- 1. Nền tảng chung ---------- */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: 72px;           /* anchor không bị header che */
}

html,
body {
    max-width: 100%;
    overflow-x: clip;                   /* chặn tràn ngang mà không phá position: sticky */
}

@supports not (overflow: clip) {
    html,
    body { overflow-x: hidden; }
}

img,
video,
iframe,
svg {
    max-width: 100%;
}

img,
video {
    height: auto;
}

body.menu-open {
    overflow: hidden;
    touch-action: none;
}

/* Vùng chạm tối thiểu 44px cho các nút/biểu tượng */
.social-links a,
.footer-social a,
.scroll-btn,
.news-tab-btn {
    min-height: 44px;
}

/* Chỉ giữ 1 nút "về đầu trang" (trang đang có 2 nút trùng nhau) */
.scroll-top {
    display: none !important;
}

/* Hộp chat không được rộng hơn màn hình */
.chatbot-popup {
    max-width: calc(100vw - 24px);
}

/* ---------- 2. Tin tức: hàng tab cuộn ngang thay vì tràn màn hình ---------- */
.news-tabs {
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .news-tabs {
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: var(--space-2);
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scroll-snap-type: x proximity;
        scroll-padding-inline: var(--space-4);
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 calc(-1 * var(--space-4)) var(--space-6);
        padding: var(--space-1) var(--space-4) var(--space-2);
    }

    .news-tabs::-webkit-scrollbar {
        display: none;
    }

    .news-tab-btn {
        flex: 0 0 auto;
        white-space: nowrap;
        scroll-snap-align: start;
        padding: 8px 18px;
        font-size: 0.95rem;
    }
}

/* Danh sách tin tự cuộn: cắt trong khung để không trượt đè lên hàng tab */
.news-tab-content.active {
    position: relative;
    max-height: 300px;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 28px), transparent 100%);
}

.news-list-container.auto-scroll {
    max-height: none;
    overflow: visible;
}

.news-list-container .news-list-item {
    line-height: 1.5;
}

/* ---------- 3. Header & menu di động ---------- */
@media (max-width: 768px) {
    .header .container {
        gap: var(--space-3);
    }

    .logo {
        min-width: 0;
        font-size: 1.15rem;
    }

    .hamburger {
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 0;
        margin-right: -4px;
        background: rgba(255, 255, 255, 0.12);
        border: 1px solid rgba(255, 255, 255, 0.25);
        border-radius: 10px;
    }

    .hamburger span {
        width: 22px;
        height: 2px;
    }

    .hamburger.active span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }

    .hamburger.active span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    /* Menu toàn màn hình, cuộn được khi mở rộng danh sách dự án */
    .navbar {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        justify-content: flex-start;
        align-items: stretch;
        gap: 2px;
        padding: 84px var(--space-5) var(--space-8);
        overflow-y: auto;
        overscroll-behavior: contain;
        transition: opacity .25s ease, transform .3s ease, visibility .3s;
    }

    .navbar > * {
        flex-shrink: 0;
    }

    body.menu-open .chatbot-fab,
    body.menu-open .back-to-top,
    body.menu-open .news-ticker-toggle {
        visibility: hidden;
    }

    .navbar > .nav-link,
    .navbar .nav-item.dropdown > .nav-link {
        display: flex;
        justify-content: space-between;
        width: 100%;
        padding: 14px 16px;
        font-size: 1.1rem;
        color: #fff;
        border-radius: 12px;
        white-space: normal;
    }

    .navbar .nav-item.dropdown {
        width: 100%;
    }

    .navbar .nav-item.dropdown > .nav-link i {
        transition: transform .25s ease;
    }

    .navbar .nav-item.dropdown.open > .nav-link i {
        transform: rotate(180deg);
    }

    /* Dropdown thành dạng "accordion" */
    .navbar .dropdown-menu {
        position: static;
        min-width: 0;
        width: 100%;
        margin: 0;
        padding: 0 0 0 var(--space-3);
        background: rgba(0, 0, 0, 0.18);
        border: 0;
        border-radius: 12px;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        display: none;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .navbar .dropdown-menu::before {
        display: none;
    }

    .navbar .nav-item.dropdown:hover .dropdown-menu {
        transform: none;
    }

    .navbar .nav-item.dropdown.open .dropdown-menu {
        display: block;
        padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
        margin: 2px 0 6px;
    }

    .navbar .dropdown-item {
        padding: 12px 10px;
        font-size: 0.98rem;
        line-height: 1.4;
        color: rgba(255, 255, 255, 0.9);
        white-space: normal;
    }

    .navbar .dropdown-item:hover {
        transform: none;
    }
}

/* Hiện chữ "FunEdu" cạnh logo (trước đây bị ẩn trên điện thoại) */
@media (max-width: 480px) {
    .logo span {
        display: inline;
    }
}

/* ---------- 4. Hero ---------- */
@media (max-width: 900px) {
    .hero-section {
        min-height: 0;
        padding: calc(64px + var(--space-8)) 0 var(--space-12);
    }

    .hero-grid {
        gap: var(--space-6);
    }

    .hero-text-left {
        margin-bottom: 0;
    }

    .hero-content-right {
        width: 100%;
        max-width: 560px;
        margin: 0 auto;
    }

    .news-ticker-wrapper {
        margin-top: 0;
    }

    .hero-image {
        display: block;
        width: 100%;
        margin-top: var(--space-5);
    }
}

@media (max-width: 640px) {
    .hero-title {
        font-size: clamp(1.45rem, 6.4vw, 1.9rem);
        line-height: 1.25;
        letter-spacing: -0.01em;
    }

    .hero-title br {
        display: none;
    }

    .hero-description-item p {
        font-size: 1rem;
        line-height: 1.55;
    }

    .hero-buttons .btn {
        max-width: none;
        min-height: 48px;
        font-size: 1rem;
    }
}

/* ---------- 5. Khối nội dung chung ---------- */
@media (max-width: 640px) {
    .section {
        padding: var(--space-12) 0;
    }

    .section-header {
        margin-bottom: var(--space-8);
    }

    .section-title {
        font-size: clamp(1.4rem, 6vw, 1.75rem);
        line-height: 1.3;
    }

    .section-subtitle {
        font-size: 1rem;
        line-height: 1.55;
    }

    .about-text p {
        font-size: 1rem;
        line-height: 1.7;
        text-align: left;
    }
}

/* Dịch vụ: 1 cột trên điện thoại nhỏ, 2 cột trên điện thoại lớn/tablet */
@media (max-width: 900px) {
    .services-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-4);
    }
}

@media (max-width: 560px) {
    .services-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }

    .service-card {
        display: grid;
        grid-template-columns: 56px 1fr;
        column-gap: var(--space-4);
        align-items: start;
        text-align: left;
        padding: var(--space-5);
    }

    .service-card .card-icon {
        grid-row: span 2;
        width: 56px;
        height: 56px;
        margin: 0;
    }

    .service-card h3 {
        font-size: 1.08rem;
        line-height: 1.35;
        margin: 0 0 var(--space-2);
    }

    .service-card p {
        font-size: 0.95rem;
        line-height: 1.6;
        margin: 0;
    }
}

/* Thống kê */
@media (max-width: 640px) {
    .stat-item p {
        font-size: 0.92rem;
        line-height: 1.4;
    }
}

/* ---------- 6. Chữ quá nhỏ (< 12px) trên điện thoại ---------- */
@media (max-width: 640px) {
    .live-indicator {
        font-size: 0.75rem;
    }

    .news-ticker-item-date,
    .news-ticker-footer a {
        font-size: 0.8rem;
    }

    .news-ticker-item-title {
        font-size: 0.95rem;
        line-height: 1.45;
    }

    .partner-item p {
        font-size: 0.78rem;
        line-height: 1.3;
    }
}

/* ---------- 7. Liên hệ, biểu mẫu & bản đồ ---------- */
@media (max-width: 768px) {
    /* 16px để iPhone không tự phóng to khi chạm vào ô nhập */
    .contact-form input,
    .contact-form textarea,
    .newsletter-form input,
    input[type="email"],
    input[type="text"],
    input[type="tel"],
    textarea {
        font-size: 16px;
    }

    .contact-info p {
        font-size: 0.98rem;
        line-height: 1.5;
        word-break: break-word;
    }

    .contact-form .btn,
    .newsletter-form button {
        min-height: 48px;
        font-size: 1rem;
    }

    .map-container iframe {
        width: 100%;
        height: 300px;
    }
}

/* ---------- 8. Footer ---------- */
@media (max-width: 640px) {
    .footer-desc {
        color: #f1e7dc;
    }

    .footer-links a,
    .footer-contact span {
        font-size: 0.98rem;
        line-height: 1.6;
    }

    .footer-links li {
        margin-bottom: 4px;
    }

    .footer-links a {
        display: inline-block;
        padding: 6px 0;
    }

    .footer-bottom p {
        font-size: 0.85rem;
        line-height: 1.5;
    }

    /* chừa chỗ cho nút chat nổi, tránh che dòng bản quyền */
    .footer-bottom {
        padding-bottom: 88px;
    }
}

/* Nút mở tin cũ không còn dùng (bảng tin đã nằm trong phần đầu trang) */
.news-ticker-toggle {
    display: none !important;
}

/* ---------- 9. Nút nổi (chat, về đầu trang) không chồng nhau ---------- */
@media (max-width: 640px) {
    .back-to-top {
        right: 16px;
        bottom: calc(84px + env(safe-area-inset-bottom, 0px));
        width: 44px;
        height: 44px;
    }
}

/* ---------- 10. Tablet ---------- */
@media (min-width: 641px) and (max-width: 1024px) {
    .container {
        padding: 0 var(--space-6);
    }

    .stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* ---------- 11. Tôn trọng thiết lập giảm chuyển động ---------- */
@media (prefers-reduced-motion: reduce) {
    .hero-title,
    .hero-description-item,
    .reveal,
    .reveal-stagger > * {
        opacity: 1 !important;
        transform: none !important;
    }
}
