/**
 * JC 導航選單樣式
 *
 * 包含桌面版 Mega Menu 和手機版側邊選單的所有樣式
 *
 * @package storefront-child
 */

/* JC Navbar 容器 */
.jc-navbar-container {
  position: relative;
  flex: 1;
  z-index: 1000;
}

/* 手機版選單切換按鈕 */
.jc-navbar-mobile-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: transparent;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  width: 40px;
  height: 40px;
}

/* 防止body滾動當選單打開時 */
body.jc-navbar-mobile-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

.jc-navbar-hamburger-line {
  width: 25px;
  height: 3px;
  background-color: #333;
  margin: 2px 0;
  transition: all 0.3s ease;
  border-radius: 2px;
}

.jc-navbar-mobile-toggle.active .jc-navbar-hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.jc-navbar-mobile-toggle.active .jc-navbar-hamburger-line:nth-child(2) {
  opacity: 0;
}

.jc-navbar-mobile-toggle.active .jc-navbar-hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -6px);
}

/* 手機版選單覆蓋層 */
.jc-navbar-mobile-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9998;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.jc-navbar-mobile-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* 手機版側邊選單 */
.jc-navbar-mobile-sidebar {
  position: fixed;
  top: 0;
  right: -350px;
  width: 350px;
  height: 100%;
  background-color: #fff;
  z-index: 9999;
  transition: all 0.3s ease;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
}

.jc-navbar-mobile-sidebar.active {
  right: 0;
}

/* 手機版選單頭部 */
.jc-navbar-mobile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #eee;
  background-color: #f8f9fa;
}

.jc-navbar-mobile-header h3 {
  margin: 0;
  color: #333;
  font-size: 1.2rem;
  font-weight: 600;
}

.jc-navbar-mobile-close {
  background: transparent;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: #666;
  transition: color 0.3s ease;
}

.jc-navbar-mobile-close:hover {
  color: #333;
}

/* 手機版選單導航 */
.jc-navbar-mobile-nav {
  padding: 1rem 0;
}

.jc-navbar-mobile-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.jc-navbar-mobile-item {
  margin: 0;
  border-bottom: 1px solid #f0f0f0;
}

.jc-navbar-mobile-item-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.jc-navbar-mobile-link {
  display: block;
  padding: 1rem 1.5rem;
  color: #666;
  text-decoration: none;
  font-size: 1rem;
  transition: all 0.3s ease;
  flex: 1;
}

.jc-navbar-mobile-link:hover {
  color: #333;
  background-color: #f8f9fa;
}

/* 手機版下拉切換按鈕 */
.jc-navbar-mobile-dropdown-toggle {
  background: transparent;
  border: none;
  padding: 1rem;
  cursor: pointer;
  color: #999;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.jc-navbar-mobile-dropdown-toggle:hover {
  color: #333;
  background-color: #f0f0f0;
}

.jc-navbar-mobile-dropdown-toggle:focus {
  outline: none;
}

.jc-navbar-mobile-dropdown-toggle.expanded {
  transform: rotate(90deg);
}

/* 手機版子選單 */
.jc-navbar-mobile-submenu {
  list-style: none;
  margin: 0;
  padding: 0;
  background-color: #f8f9fa;
  max-height: 0;
  overflow: hidden;
  transition: all 0.3s ease;
}

.jc-navbar-mobile-submenu.expanded {
  max-height: 1000px;
}

.jc-navbar-mobile-submenu .jc-navbar-mobile-item {
  border-bottom: 1px solid #e9ecef;
}

.jc-navbar-mobile-submenu .jc-navbar-mobile-link {
  padding-left: 2.5rem;
  font-size: 0.9rem;
  color: #777;
}

.jc-navbar-mobile-submenu .jc-navbar-mobile-submenu .jc-navbar-mobile-link {
  padding-left: 3.5rem;
  font-size: 0.85rem;
  color: #888;
}

.jc-navbar-mobile-submenu
  .jc-navbar-mobile-submenu
  .jc-navbar-mobile-submenu
  .jc-navbar-mobile-link {
  padding-left: 4.5rem;
  font-size: 0.8rem;
  color: #999;
}

/* 桌面版選單 */
.jc-navbar-desktop-only {
  display: block;
}

.jc-navbar-mega-nav {
  width: 100%;
}

.jc-navbar-mega-list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  justify-content: flex-end;
}

.jc-navbar-mega-item {
  position: relative;
  margin: 0;
  padding: 0;
}

/* 添加虛擬元素來填補空隙 */
.jc-navbar-mega-item::after {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: -20px; /* 延伸到下拉選單 */
  height: 20px;
  background: transparent;
}

.jc-navbar-mega-link {
  display: block;
  padding: 1rem 1.5rem;
  color: #333;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
}

.jc-navbar-mega-link:focus {
  outline: none;
}

.jc-navbar-mega-link:hover {
  color: #f8b332;
}

/* 下拉選單容器 - 填滿畫面 */
.jc-navbar-mega-dropdown {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  top: var(--header-height, 80px);
  background: #fff;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  padding: 2rem 10rem;
  z-index: 1000;
  width: 100%;
  max-height: 45vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* 為iOS添加平滑滾動 */
  overscroll-behavior: contain; /* 防止滾動傳播 */
}

/* 當下拉選單啟用時顯示 */
.jc-navbar-mega-item:hover .jc-navbar-mega-dropdown,
.jc-navbar-mega-dropdown.active {
  display: flex !important;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 100%;
  margin: 0 auto;
  left: 50%;
  transform: translateX(-50%);
}

/* 第二層標題列 */
.jc-navbar-mega-column {
  flex: 1;
  min-width: 250px;
  max-width: 300px;
  display: block !important;
  padding: 0 1rem;
}

.jc-navbar-mega-title {
  color: #333;
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #f8b332;
  text-decoration: none;
  display: block;
  transition: all 0.3s ease;
}

.jc-navbar-mega-title:hover {
  color: #f8b332;
}

.jc-navbar-mega-title:focus {
  outline: none;
}

/* 第三層選單列表 */
.jc-navbar-mega-sub-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.jc-navbar-mega-sub-item {
  margin: 0;
  padding: 0;
  position: relative;
}

/* 第4層選單項目默認隱藏 */
.jc-navbar-mega-sub-item.jc-navbar-fourth-level {
  display: none;
}

/* 更深層級的選單項目默認隱藏 */
.jc-navbar-mega-sub-item.jc-navbar-deeper-level {
  display: none;
}

/* 包裝容器樣式 */
.jc-navbar-mega-sub-item-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 0;
}

/* 連結樣式 */
.jc-navbar-mega-sub-link {
  display: block;
  color: #666;
  text-decoration: none;
  transition: all 0.3s ease;
  flex: 1;
  padding: 0;
}

.jc-navbar-mega-sub-link:focus {
  outline: none;
}

.jc-navbar-mega-sub-link:hover {
  color: #f8b332;
}

/* 沒有子選單的項目padding */
.jc-navbar-mega-sub-item:not(.jc-navbar-has-children) .jc-navbar-mega-sub-link {
  padding: 0.8rem 0;
}

/* 下拉圖標按鈕樣式 */
.jc-navbar-dropdown-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0.5rem;
  margin-left: 0.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #666;
  min-width: 32px;
  height: 32px;
  border-radius: 4px;
}

.jc-navbar-dropdown-icon:hover {
  background-color: rgba(248, 179, 50, 0.1);
  color: #f8b332;
}

.jc-navbar-dropdown-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

/* 深層下拉選單 */
.jc-navbar-mega-deep-dropdown {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  top: var(--header-height, 80px);
  background: #fff;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  padding: 2rem;
  z-index: 1001;
  width: 100%;
}

.jc-navbar-mega-deep-dropdown.active {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
  margin: 0 auto;
  left: 50%;
  transform: translateX(-50%);
}

/* 響應式設計 */
@media (max-width: 1024px) {
  .jc-navbar-mobile-toggle {
    display: flex;
    order: -1; /* 確保在最前面 */
  }

  .jc-navbar-desktop-only {
    display: none;
  }

  .jc-navbar-mobile-sidebar {
    width: 320px;
    right: -320px;
  }
}

@media (max-width: 768px) {
  /* 移動端不需要虛擬元素 */
  .jc-navbar-mega-item::after {
    display: none;
  }

  .jc-navbar-mobile-sidebar {
    width: 280px;
    right: -280px;
  }

  .jc-navbar-mobile-header {
    padding: 0.8rem 1rem;
  }

  .jc-navbar-mobile-link {
    padding: 0.8rem 1rem;
    font-size: 0.9rem;
  }

  .jc-navbar-mega-dropdown,
  .jc-navbar-mega-deep-dropdown {
    position: static;
    transform: none;
    left: 0;
    width: 100%;
    margin: 0;
  }

  .jc-navbar-mega-sub-item-wrapper {
    padding: 0.6rem 0;
  }

  .jc-navbar-dropdown-icon {
    padding: 0.4rem;
    min-width: 28px;
    height: 28px;
  }
}

@media (max-width: 480px) {
  .jc-navbar-mobile-sidebar {
    width: 100%;
    right: -100%;
  }

  .jc-navbar-mobile-header h3 {
    font-size: 1.1rem;
  }

  .jc-navbar-mobile-link {
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
  }
}

/* 平板模式優化 */
@media (min-width: 769px) and (max-width: 1024px) {
  .jc-navbar-mega-link {
    padding: 0.9rem 1.2rem;
    font-size: 0.95rem;
  }

  .jc-navbar-mega-dropdown {
    padding: 1.5rem;
    max-width: 95%;
  }

  .jc-navbar-mega-column {
    min-width: 200px;
    max-width: 250px;
    padding: 0 0.8rem;
  }

  .jc-navbar-mega-title {
    font-size: 1.1rem;
  }

  .jc-navbar-mega-sub-item-wrapper {
    padding: 0.7rem 0;
  }
}
