/**
 * Stylesheet cho Menu Dòng xe & Phụ tùng theo xe
 * Phụ tùng ô tô Thành Dũng (Flatsome Child Theme)
 */

/* ==========================================================================
   1. Menu Dòng Xe [get-content-menu]
   ========================================================================== */
.th-menu-dongxe {
    display: grid;
    grid-template-columns: repeat(var(--cols, 3), 1fr);
    gap: 16px;
    margin: 1.5rem 0;
}

.th-menu-dongxe ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.th-menu-dongxe li.menu {
    position: relative;
    margin-bottom: 6px;
}

.th-menu-dongxe li.menu > a {
    display: block;
    padding: 9px 12px;
    background: #ffffff;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    font-weight: 600;
    color: #2d3748;
    transition: all 0.2s ease-in-out;
    text-decoration: none;
}

.th-menu-dongxe li.menu:hover > a,
.th-menu-dongxe li.menu:focus-within > a {
    background: #0288d1;
    color: #fff;
    border-color: #0288d1;
}

.th-menu-dongxe .submenu {
    display: none;
    background: #fff;
    padding: 6px 0;
}

.th-menu-dongxe .submenu li a {
    display: block;
    padding: 7px 14px;
    color: #4a5568;
    font-size: 14px;
    transition: 0.15s;
    text-decoration: none;
}

.th-menu-dongxe .submenu li:hover a,
.th-menu-dongxe .submenu li a:focus {
    background: #0288d1;
    color: #fff !important;
}

/* Nút mở menu con chỉ dùng trên mobile */
.th-submenu-toggle {
    display: none;
}

/* Desktop: menu con bay ra bên cạnh khi hover/focus */
@media (min-width: 769px) {
    .th-menu-dongxe .submenu {
        position: absolute;
        top: 0;
        left: 100%;
        margin-left: 6px;
        min-width: 230px;
        max-height: 70vh;
        overflow-y: auto;
        border-radius: 6px;
        border: 1px solid #cbd5e0;
        box-shadow: 0 8px 20px rgba(0,0,0,0.14);
        z-index: 9999;
    }

    /* Cầu nối lấp khe 6px để không mất hover khi rê chuột sang menu con */
    .th-menu-dongxe li.has-children::after {
        content: "";
        position: absolute;
        top: 0;
        left: 100%;
        width: 8px;
        height: 100%;
        display: none;
    }

    .th-menu-dongxe li.menu:hover > .submenu,
    .th-menu-dongxe li.menu:focus-within > .submenu,
    .th-menu-dongxe li.has-children:hover::after {
        display: block;
    }

    /* Cột cuối: mở menu con sang trái để không tràn màn hình */
    .th-menu-dongxe .menu-col:last-child:not(:first-child) .submenu {
        left: auto;
        right: 100%;
        margin-left: 0;
        margin-right: 6px;
    }

    .th-menu-dongxe .menu-col:last-child:not(:first-child) li.has-children::after {
        left: auto;
        right: 100%;
    }
}

/* Mobile: 1 cột, menu con mở bằng nút */
@media (max-width: 768px) {
    .th-menu-dongxe {
        grid-template-columns: 1fr;
    }

    .th-menu-dongxe li.has-children {
        display: flex;
        flex-wrap: wrap;
    }

    .th-menu-dongxe li.has-children > a {
        flex: 1;
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
    }

    .th-submenu-toggle {
        display: block;
        position: relative;
        width: 42px;
        min-height: 0;
        margin: 0;
        padding: 0;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-left: 0;
        border-radius: 0 6px 6px 0;
        cursor: pointer;
    }

    .th-submenu-toggle::before {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        width: 8px;
        height: 8px;
        border-right: 2px solid #4a5568;
        border-bottom: 2px solid #4a5568;
        transform: translate(-50%, -75%) rotate(45deg);
        transition: transform 0.2s;
    }

    .th-menu-dongxe li.is-open > .th-submenu-toggle::before {
        transform: translate(-50%, -25%) rotate(-135deg);
    }

    .th-menu-dongxe .submenu {
        flex-basis: 100%;
        padding-left: 15px;
    }

    .th-menu-dongxe li.is-open > .submenu {
        display: block;
    }
}

/* Menu Dòng xe Mobile [menu-dongxe-mobile] */
.th-menu-dongxe-mobile {
    list-style: none;
    padding: 0;
    margin: 0;
}

.th-menu-dongxe-mobile li {
    margin-bottom: 5px;
}

.th-menu-dongxe-mobile li a {
    display: block;
    padding: 8px 12px;
    background: #fff;
    border-bottom: 1px solid #eee;
    color: #333;
    text-decoration: none;
    font-weight: 600;
}

.th-menu-dongxe-mobile ul.children {
    list-style: none;
    padding-left: 15px;
    margin: 5px 0;
}

.th-menu-dongxe-mobile ul.children li a {
    font-weight: normal;
    color: #666;
    border-bottom: 1px dashed #f0f0f0;
}

/* ==========================================================================
   2. Phụ Tùng Theo Xe [phu_tung_theo_xe]
   ========================================================================== */
.th-ptx {
    margin: 1.5rem 0;
}

.th-ptx-title {
    font-size: 1.4rem;
    font-weight: bold;
    margin-bottom: 1rem;
    color: #1a202c;
}

.th-ptx-list {
    display: grid;
    grid-template-columns: repeat(var(--cols-desktop, 6), minmax(0, 1fr));
    gap: 14px;
}

.th-ptx-item {
    display: block;
    text-decoration: none;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    transition: all 0.2s ease-in-out;
}

.th-ptx-item:hover,
.th-ptx-item:focus {
    border-color: #0288d1;
    box-shadow: 0 4px 12px rgba(2,136,209,0.15);
    transform: translateY(-2px);
}

.th-ptx-item-title {
    display: block;
    font-weight: 600;
    font-size: 14px;
    color: #2d3748;
    line-height: 1.35;
}

@media (max-width: 768px) {
    .th-ptx-list {
        grid-template-columns: repeat(var(--cols-mobile, 3), minmax(0, 1fr));
        gap: 10px;
    }
}
