﻿/* =====================================================================
   CSS MENU HOÀN CHỈNH - CĂN CÂN BẰNG NỘI DUNG THEO KHUNG 1200PX
   ===================================================================== */

/* Khung bao ngoài toàn bộ menu - Vẫn tràn 100% dải nền xanh */
#cssmenu {
  background: linear-gradient(90deg, rgb(27, 94, 32) 0%, rgb(46, 125, 50) 100%);
  border-top: none;
  margin: 0;
  width: 100% !important;
  padding: 0;
  position: relative;
  font-family: 'Be Vietnam Pro', Arial, 'Segoe UI', sans-serif;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  border-radius: 0;
  box-sizing: border-box;
}

/* Reset danh sách <ul> - ĐÃ THÊM PADDING LÙI VÀO KHUNG 1200PX */
#cssmenu > ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  float: left !important;
  box-sizing: border-box;
  padding-left: max(10px, calc((100% - 1200px) / 2 + 6px)) !important;
}

/* Clearfix */
#cssmenu ul:after,
#cssmenu:after {
  content: " ";
  display: block;
  font-size: 0;
  height: 0;
  clear: both;
  visibility: hidden;
}

/* Thiết lập chung cho mọi <li> trong menu */
#cssmenu ul li {
  margin: 0;
  padding: 0;
  display: block;
  position: relative;
  z-index: 1000;
}

/* Thiết lập link <a> */
#cssmenu ul li a {
  text-decoration: none;
  display: block;
  margin: 0;
  transition: all .2s ease;
  box-sizing: border-box;
}

/* ---------------------------------------------------------------------
   CẤP 1: MENU NGANG XANH LÁ GRADIENT (DESKTOP > 768PX)
   --------------------------------------------------------------------- */
#cssmenu > ul > li {
  float: left !important;
  width: auto;
  padding: 3px 4px;
  box-sizing: border-box;
}

#cssmenu > ul > li > a {
  color: #ffffff;
  padding: 8px 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-size: 14px;
  line-height: 1.2;
  z-index: 200;
  position: relative;
  border-radius: 5px;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
}

#cssmenu > ul > li:after,
#cssmenu > ul > li > a:after {
  display: none !important;
}

/* Khi Hover hoặc Active vào mục Cấp 1 */
#cssmenu > ul > li:hover > a,
#cssmenu > ul > li.active > a {
  color: #ffffff !important;
  background: #47804b !important;
  border-bottom-color: #fcd34d !important;
}

#cssmenu > ul > li:has(ul) > a,
#cssmenu > ul > li.has-sub > a {
  padding-right: 38px !important;
}

/* MŨI TÊN CẤP 1 TRỎ XUỐNG (DESKTOP) */
#cssmenu > ul > li:has(ul) > a::before,
#cssmenu > ul > li.has-sub > a::before {
  content: "" !important;
  display: block !important;
  position: absolute !important;
  right: 14px !important;
  top: 50% !important;
  width: 9px !important;
  height: 9px !important;
  border-right: 3px solid #ffffff !important;
  border-bottom: 3px solid #ffffff !important;
  border-top: none !important;
  border-left: none !important;
  border-bottom-right-radius: 2px !important;
  transform: translateY(-65%) rotate(45deg) !important;
  transition: transform 0.25s ease, border-color 0.25s ease !important;
}

/* MŨI TÊN CẤP 1 XOAY LÊN KHI HOVER (DESKTOP) */
#cssmenu > ul > li:has(ul):hover > a::before,
#cssmenu > ul > li.has-sub:hover > a::before,
#cssmenu > ul > li.active > a::before {
  transform: translateY(-35%) rotate(225deg) !important;
  border-color: #ffffff !important;
}

/* ---------------------------------------------------------------------
   CẤP 2: DROPDOWN MENU (DESKTOP)
   --------------------------------------------------------------------- */
#cssmenu ul li ul {
  position: absolute;
  left: -9999px;
  top: 100%;
  min-width: 280px !important;
  background: rgb(254, 252, 232) !important;
  border-width: 1px;
  border-style: solid;
  border-color: rgb(217, 119, 6) rgb(252, 211, 77) rgb(252, 211, 77);
  border-image: none;
  border-radius: 0px 0px 10px 10px;
  box-shadow: rgba(0, 0, 0, 0.15) 0px 8px 24px;
  padding: 6px 0px;
  margin: 0;
  z-index: 2000;
  opacity: 0;
  transform: translateY(-5px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}

#cssmenu > ul > li:hover > ul {
  left: 4px !important;
  opacity: 1;
  transform: translateY(0px);
  pointer-events: auto;
}

#cssmenu ul li ul li {
  position: relative;
  max-height: none;
  width: 100%;
  display: block;
  background: transparent;
  margin-bottom: 0;
  overflow: visible !important;
  border-bottom: 1px solid rgba(217, 119, 6, 0.2) !important;
}

#cssmenu ul li ul li:last-child {
  border-bottom: none !important;
}

#cssmenu ul li ul li a {
  font-size: 13.5px;
  font-weight: 500;
  text-transform: none;
  color: #1b5e20 !important;
  letter-spacing: 0;
  display: block;
  width: 100%;
  padding: 10px 16px;
  border-radius: 0;
  border: none;
  box-sizing: border-box;
  background: transparent;
}

#cssmenu ul li ul li:has(ul) > a,
#cssmenu ul li ul li.has-sub > a {
  padding-right: 32px !important;
}

#cssmenu ul li ul li:hover > a,
#cssmenu ul li ul li.active > a {
  color: rgb(146, 64, 14) !important;
  font-weight: 600 !important;
  background: rgba(180, 83, 9, 0.08) !important;
}

#cssmenu ul li ul li:has(ul) > a:after,
#cssmenu ul li ul li.has-sub > a:after {
  content: "" !important;
  display: block !important;
  position: absolute !important;
  right: 14px !important;
  top: 50% !important;
  width: 8px !important;
  height: 8px !important;
  border-right: 2.5px solid #1b5e20 !important;
  border-top: 2.5px solid #1b5e20 !important;
  border-left: none !important;
  border-bottom: none !important;
  border-radius: 1px !important;
  transform: translateY(-50%) rotate(45deg) !important;
  transition: border-color 0.2s ease, transform 0.2s ease !important;
}

#cssmenu ul li ul li:has(ul):hover > a:after,
#cssmenu ul li ul li.has-sub:hover > a:after {
  border-color: rgb(146, 64, 14) !important;
  transform: translateY(-50%) rotate(45deg) translateX(2px) !important;
}

/* ---------------------------------------------------------------------
   CẤP 3: DROPDOWN MENU (DESKTOP)
   --------------------------------------------------------------------- */
#cssmenu ul li ul li ul {
  top: -3px;
  left: -9999px;
  min-width: 240px !important;
  background: rgb(254, 252, 232) !important;
  border: 1px solid rgb(252, 211, 77);
  border-radius: 8px;
  box-shadow: rgba(0, 0, 0, 0.15) 0px 8px 24px;
  padding: 6px 0;
  z-index: 3000;
}

#cssmenu ul li ul li:hover > ul {
  left: 100% !important;
  right: auto !important;
  opacity: 1;
  transform: translateY(0px);
  pointer-events: auto;
}

#cssmenu ul li ul li:has(ul)::after,
#cssmenu ul li ul li.has-sub::after {
  content: "";
  position: absolute;
  top: 0;
  right: -10px;
  width: 15px;
  height: 100%;
  background: transparent !important;
  z-index: 2500;
  display: block;
}

#cssmenu #menu-button { display: none; }
/* Desktop: chỉ hiện icon, ẩn chữ */
#cssmenu .home-text { display: none; }
#cssmenu .menu-close-li { display: none; }
.menu-overlay { display: none; }
#cssmenu .menu-popover { display: none; }
.tools-close-btn { display: none; }

/* ---------------------------------------------------------------------
   RESPONSIVE (MOBILE & TABLET <= 768PX ACCORDION)
   --------------------------------------------------------------------- */
@media all and (max-width: 768px) {
  #cssmenu {
    padding: 0;
  }

  /* DRAWER: trượt từ trái sang, rộng 2/3 màn hình, có thanh cuộn */
  #cssmenu > ul {
    padding-left: 0 !important;
    padding-bottom: 80px !important;
    display: block;
    float: none !important;
    background: linear-gradient(180deg, rgb(27, 94, 32) 0%, rgb(46, 125, 50) 100%);

    position: fixed;
    top: 0;
    left: 0;
    width: 66.667vw !important;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    z-index: 99999;
    box-sizing: border-box;

    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;

    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.6) rgba(0, 0, 0, 0.2);

    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);

    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.3s ease, visibility 0.3s;
  }

  #cssmenu > ul::-webkit-scrollbar {
    width: 6px;
  }
  #cssmenu > ul::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
  }
  #cssmenu > ul::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.6);
    border-radius: 3px;
  }

  #cssmenu > ul.drawer-open {
    transform: translateX(0);
    visibility: visible;
  }

  /* Nút X đóng menu - dính ở đầu menu khi cuộn */
  #cssmenu .menu-close-li {
    display: flex;
    justify-content: flex-end;
    padding: 8px 10px;
    background: rgb(27, 94, 32);
    position: sticky;
    top: 0;
    z-index: 100000;
  }

  #cssmenu .menu-close-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }

  #cssmenu .menu-close-btn:active {
    background: rgba(255, 255, 255, 0.3);
  }

  /* Lớp nền mờ phía sau drawer */
  .menu-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s;
    touch-action: none;
    overscroll-behavior: contain;
  }

  .menu-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  /* Khóa cuộn trang khi mở drawer */
  html.menu-lock,
  body.menu-lock {
    overflow: hidden !important;
    height: 100%;
  }

  /* ===== DRAWER "DANH MỤC" (menu dọc) ===== */
  #toolsDrawer {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 66.667vw !important;
    height: 100vh;
    height: 100dvh;
    margin: 0 !important;
    padding: 0 0 80px 0 !important;
    float: none !important;
    z-index: 99999;
    box-sizing: border-box;

    background: linear-gradient(180deg, rgb(27, 94, 32) 0%, rgb(46, 125, 50) 100%);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);

    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.3s ease, visibility 0.3s;
  }

  #toolsDrawer.drawer-open {
    transform: translateX(0);
    visibility: visible;
  }

  #toolsDrawer .tools-close-btn {
    position: sticky;
    top: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: 8px 10px 8px auto;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
  }

  /* POPOVER hiện ra khi bấm nút 3 gạch */
  #cssmenu .menu-popover {
    display: block;
    position: absolute;
    top: 100%;
    right: 12px;
    margin-top: 6px;
    min-width: 240px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    z-index: 99997;

    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  }

  #cssmenu .menu-popover.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  #cssmenu .menu-popover-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 18px 24px;
    border: none;
    background: transparent;
    color: #1f2937;
    font-family: inherit;
    font-size: 17px;
    text-align: left;
    cursor: pointer;
  }

  #cssmenu .menu-popover-item + .menu-popover-item {
    border-top: 1px solid #e5e7eb;
  }

  #cssmenu .menu-popover-item:active {
    background: #f3f4f6;
  }

  #cssmenu .menu-popover-item .bi {
    font-size: 20px;
    line-height: 1;
    color: #1b5e20;
    flex-shrink: 0;
  }

  #cssmenu ul li {
    float: none !important;
    width: 100%;
  }

  /* ===== Thanh tiêu đề: chữ (về trang chủ) + icon 3 gạch (mở popover) ===== */
  #cssmenu #menu-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 1px;
    color: #ffffff;
    position: relative;
    background: linear-gradient(90deg, rgb(27, 94, 32) 0%, rgb(46, 125, 50) 100%);
    box-sizing: border-box;
  }

  /* Chữ -> link về trang chủ */
  #cssmenu #menu-button .menu-title-link {
    flex: 1;
    padding: 15px 0 15px 20px;
    color: #ffffff !important;
    text-decoration: none !important;
  }

  /* Vùng bấm icon 3 gạch -> mở popover */
  #cssmenu #menu-button .menu-toggle-icon {
    width: 64px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
  }

  /* Icon 3 gạch của Bootstrap Icons (bi-list, mã \f479) */
  #cssmenu #menu-button .menu-toggle-icon:after {
    content: "\f479";
    font-family: "bootstrap-icons" !important;
    font-style: normal;
    font-weight: normal;
    line-height: 1;
    font-size: 32px;
    color: #ffffff;
  }

  /* Link menu Cấp 1 */
  #cssmenu > ul > li > a {
    width: 100%;
    padding: 12px 45px 12px 20px;
    background: transparent;
    color: #ffffff !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  /* Reset & ẩn các danh sách sub-menu con */
  #cssmenu ul li ul,
  #cssmenu ul li ul li ul {
    display: none;
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    box-shadow: none !important;
    border: none !important;
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
    padding: 0 !important;
  }

  /* Mở sub-menu khi bấm toggle */
  #cssmenu ul li.submenu-open > ul {
    display: block !important;
  }

  /* Vô hiệu hóa hiệu ứng hover của desktop trên mobile */
  #cssmenu > ul > li:hover > ul,
  #cssmenu ul li ul li:hover > ul {
    left: 0 !important;
    right: auto !important;
    top: 0 !important;
    opacity: 1 !important;
    transform: none !important;
  }

  /* --- CẤP 2 (MENU CON) --- */
  #cssmenu ul li ul li a {
    padding-left: 35px !important;
    color: #1b5e20 !important;
    background: rgb(254, 249, 195) !important;
    border-bottom: 1px solid rgba(217, 119, 6, 0.2) !important;
    font-weight: 500;
  }

  /* --- CẤP 3 (MENU CON CỦA CẤP 2) --- */
  #cssmenu ul li ul li ul li a {
    padding-left: 50px !important;
    color: #78350f !important;
    background: #fcd34d !important;
    border-bottom: 1px solid rgba(180, 83, 9, 0.2) !important;
    font-weight: 500;
  }

  /* ẨN MŨI TÊN CŨ VÀ CẦU NỐI HOVER DÙNG TRÊN DESKTOP */
  #cssmenu ul li:has(ul) > a::before,
  #cssmenu ul li.has-sub > a::before,
  #cssmenu ul li ul li:has(ul)::after,
  #cssmenu ul li ul li.has-sub::after {
    display: none !important;
  }

  /* MŨI TÊN TRỎ XUỐNG CHO MOBILE (V) - TRẠNG THÁI ĐÓNG */
  #cssmenu li.has-sub > a,
  #cssmenu li:has(ul) > a {
    position: relative;
  }

  #cssmenu li.has-sub > a::after,
  #cssmenu li:has(ul) > a::after,
  #cssmenu ul li ul li:has(ul) > a::after,
  #cssmenu ul li ul li.has-sub > a::after {
    content: "" !important;
    display: block !important;
    position: absolute !important;
    right: 20px !important;
    top: 50% !important;
    width: 8px !important;
    height: 8px !important;
    border-right: 2px solid currentColor !important;
    border-bottom: 2px solid currentColor !important;
    border-top: none !important;
    border-left: none !important;
    border-radius: 1px !important;
    transform: translateY(-60%) rotate(45deg) !important;
    transition: transform 0.25s ease !important;
  }

  /* Chặn hiệu ứng hover của desktop làm lệch mũi tên */
  #cssmenu ul li ul li:has(ul):hover > a::after,
  #cssmenu ul li ul li.has-sub:hover > a::after {
    border-color: currentColor !important;
    transform: translateY(-60%) rotate(45deg) !important;
  }

  /* XOAY MŨI TÊN HƯỚNG LÊN (^) KHI MỞ MENU CON - PHẢI ĐỂ SAU CÙNG */
  #cssmenu li.submenu-open > a::after,
  #cssmenu ul li.submenu-open > a::after,
  #cssmenu ul li ul li.submenu-open > a::after,
  #cssmenu ul li ul li:has(ul).submenu-open > a::after,
  #cssmenu ul li ul li.has-sub.submenu-open > a::after,
  #cssmenu ul li ul li:has(ul).submenu-open:hover > a::after,
  #cssmenu ul li ul li.has-sub.submenu-open:hover > a::after {
    transform: translateY(-20%) rotate(225deg) !important;
  }

  #cssmenu ul li ul,
  #cssmenu ul li ul li ul {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  /* Chừa chỗ cho mũi tên, tránh chữ đè lên */
  #cssmenu ul li ul li:has(ul) > a,
  #cssmenu ul li ul li.has-sub > a {
    padding-right: 44px !important;
  }

  /* Mũi tên menu con nằm gọn trong dòng */
  #cssmenu ul li ul li:has(ul) > a::after,
  #cssmenu ul li ul li.has-sub > a::after {
    right: 18px !important;
  }

  /* Mobile: ẩn icon, hiện chữ "Trang chủ" */
  #cssmenu .home-item .ti-home { display: none; }
  #cssmenu .home-item .home-text { display: inline; }
}