﻿/* =====================================================================
   BỘ CSS MENU DỌC (MENU-V) HOÀN CHỈNH
   ===================================================================== */

/* 1. KHUNG BAO NGOÀI TOÀN BỘ MENU DỌC */
#menu-v {
    width: 100%;
    list-style: none;
    margin: 0;
    padding: 0;
    display: block;
    position: relative !important;
    background: #295D37;
    border: 1px solid #1f472a;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    overflow: visible !important;
    z-index: 999 !important;
}

#menu-v > li {
    background: transparent;
    list-style: none;
    margin: 0;
    padding: 0;
    position: relative !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

#menu-v > li:first-child,
#menu-v > li:first-child > a {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

#menu-v > li:last-child {
    border-bottom: none;
}

#menu-v > li:last-child,
#menu-v > li:last-child > a {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

/* 2. LINK CẤP 1 (MENU CHA) */
#menu-v > li > a {
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    color: #ffffff !important;
    text-decoration: none;

    min-height: 48px !important;
    line-height: 1.4 !important;
    padding: 12px 18px !important;

    background: #295D37 !important;
    position: relative;
    overflow: hidden;
    white-space: normal;
    word-wrap: break-word;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

#menu-v > li:hover > a,
#menu-v > li.active > a {
    color: #3c763d !important;
    background: #d8ebd0 !important;
    font-weight: 700;
}

#menu-v > li > a::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 5px;
    height: 100%;
    background: #6fa05a;
    opacity: 0;
    transition: opacity 0.2s ease;
}

#menu-v > li:hover > a::before,
#menu-v > li.active > a::before {
    opacity: 1;
}

/* 3. SUBMENU CẤP 2 & CẤP 3 (MENU CON SỔ NGANG) */
#menu-v li ul {
    position: absolute !important;
    left: 100% !important;
    top: 0 !important;

    min-width: 320px;
    width: max-content;
    max-width: 450px;

    background: #295D37 !important;
    border: 1px solid #1f472a;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    padding: 0;
    overflow: visible !important;
    visibility: hidden;
    opacity: 0;
    z-index: 999999 !important;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

#menu-v li:hover > ul {
    visibility: visible !important;
    opacity: 1 !important;
}

#menu-v ul li {
    background: transparent;
    margin: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    list-style: none;
    position: relative !important;
}

#menu-v ul li:last-child {
    border-bottom: none;
}

#menu-v ul li:first-child,
#menu-v ul li:first-child > a {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

#menu-v ul li:last-child,
#menu-v ul li:last-child > a {
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

#menu-v ul li a {
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #ffffff !important;
    display: flex;
    align-items: center;
    text-decoration: none;

    min-height: 48px !important;
    line-height: 1.4 !important;
    padding: 12px 20px !important;

    background: #295D37 !important;
    position: relative;
    overflow: hidden;
    white-space: normal;
    word-wrap: break-word;
    transition: all 0.15s ease;
    box-sizing: border-box;
}

#menu-v ul li a:hover,
#menu-v ul li.active > a {
    background: #d8ebd0 !important;
    color: #3c763d !important;
    font-weight: 700;
}

#menu-v ul li a::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: #6fa05a;
    opacity: 0;
    transition: opacity 0.15s ease;
}

#menu-v ul li a:hover::before,
#menu-v ul li.active > a::before {
    opacity: 1;
}

/* 4. MŨI TÊN BÊN PHẢI (>) */
#menu-v li:has(ul) > a,
#menu-v li.has-sub > a {
    padding-right: 36px !important;
}

#menu-v li:has(ul) > a::after,
#menu-v li.has-sub > a::after {
    content: "" !important;
    display: block !important;
    position: absolute !important;
    right: 14px !important;
    top: 50% !important;
    width: 7px !important;
    height: 7px !important;
    border-right: 2px solid #ffffff !important;
    border-top: 2px solid #ffffff !important;
    transform: translateY(-50%) rotate(45deg) !important;
    transition: all 0.2s ease !important;
    box-sizing: border-box !important;
}

#menu-v li:has(ul):hover > a::after,
#menu-v li.has-sub:hover > a::after,
#menu-v li.active > a::after {
    border-color: #3c763d !important;
    transform: translateY(-50%) rotate(45deg) translateX(2px) !important;
}

/* Cầu nối vùng rê chuột */
#menu-v li:hover::after {
    content: "";
    position: absolute;
    top: 0;
    right: -10px;
    width: 15px;
    height: 100%;
    z-index: 99999;
}

/* Submenu Cấp 3 */
#menu-v ul li ul {
    left: 100% !important;
    top: 0 !important;
}

/* 5. RESPONSIVE MOBILE: menu con xổ xuống tại chỗ (accordion) */
@media screen and (max-width: 768px) {

    #menu-v {
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    #menu-v > li:first-child, #menu-v > li:first-child > a,
    #menu-v > li:last-child, #menu-v > li:last-child > a,
    #menu-v ul li:first-child, #menu-v ul li:first-child > a,
    #menu-v ul li:last-child, #menu-v ul li:last-child > a {
        border-radius: 0 !important;
    }

    #menu-v li ul,
    #menu-v li ul li ul {
        position: static !important;
        transform: none !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: rgba(0, 0, 0, 0.18) !important;
        display: none !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    #menu-v li.submenu-open > ul {
        display: block !important;
    }

    #menu-v ul li a { padding-left: 32px !important; }
    #menu-v ul li ul li a { padding-left: 46px !important; }

    /* Tắt hover dính trên cảm ứng */
    #menu-v > li:hover > a {
        background: #295D37 !important;
        color: #ffffff !important;
        font-weight: 500;
    }
    #menu-v ul li a:hover {
        background: transparent !important;
        color: #ffffff !important;
        font-weight: 600;
    }
    #menu-v > li:hover > a::before,
    #menu-v ul li a:hover::before { opacity: 0; }
    #menu-v li:hover::after { display: none !important; }

    /* Mục đang mở */
    #menu-v li.submenu-open > a {
        background: #d8ebd0 !important;
        color: #3c763d !important;
        font-weight: 700;
    }

    /* Mũi tên: xuống khi đóng, lên khi mở */
    #menu-v li:has(ul) > a::after,
    #menu-v li.has-sub > a::after,
    #menu-v li:has(ul):hover > a::after,
    #menu-v li.has-sub:hover > a::after {
        border-right: 2px solid currentColor !important;
        border-bottom: 2px solid currentColor !important;
        border-top: none !important;
        border-left: none !important;
        border-color: currentColor !important;
        transform: translateY(-60%) rotate(45deg) !important;
    }
    /* Mở: mũi tên hướng lên (kể cả khi đang hover/chạm) */
    #menu-v li.submenu-open > a::after,
    #menu-v li.submenu-open:hover > a::after,
    #menu-v li.submenu-open:has(ul) > a::after,
    #menu-v li.submenu-open:has(ul):hover > a::after,
    #menu-v li.has-sub.submenu-open:hover > a::after {
        transform: translateY(-20%) rotate(225deg) !important;
    }

    /* 1. Ẩn mũi tên ::after cũ dính trên thẻ <a> */
    #menu-v li:has(ul) > a::after,
    #menu-v li.has-sub > a::after {
        display: none !important;
    }

    /* 2. Đặt vị trí cho nút mũi tên mới tạo */
    #menu-v li {
        position: relative !important;
    }

    #menu-v .arrow-toggle {
        position: absolute;
        right: 0;
        top: 0;
        width: 50px;
        height: 48px;
        z-index: 10;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Vẽ hình mũi tên HƯỚNG XUỐNG (khi đang đóng) */
    #menu-v .arrow-toggle::after {
        content: "";
        display: block;
        width: 7px;
        height: 7px;
        border-right: 2px solid #ffffff;
        border-bottom: 2px solid #ffffff;
        transform: rotate(45deg); /* Mặc định trỏ xuống */
        transition: transform 0.25s ease, border-color 0.25s ease;
    }

    /* 3. Xoay HƯỚNG LÊN (khi menu mở - có class .submenu-open) */
    #menu-v li.submenu-open > .arrow-toggle::after {
        transform: rotate(225deg); /* Quay 180 độ thành hướng lên */
        border-color: #3c763d; /* Đổi màu mũi tên cho nổi bật nếu cần */
    }
}