/* ===========================================================
   Artist Mega Menu for Elementor — 整理版 CSS（包含水平對齊修正與 fallback）
   放在 style.css 末端或 .cme-megamenu 原始定義後
   =========================================================== */

/* ---------- 基本 reset / 變數 ---------- */
:root {
  /* 預設對齊，可被 inline style 或 Elementor selectors 覆寫 */
  --cme-justify: flex-start;
}

/* ---------- 外層 wrapper（確保有寬度空間供 justify-content 使用） ---------- */
.cme-menu-wrapper {
  display: block;
  width: 100%;
  box-sizing: border-box;
  position: relative; /* 保留給 backdrop / hamburger 用 */
}

/* ---------- 主要 UL（base） ---------- */
.cme-megamenu {
  /* 基本外觀 */
  background: var(--cme-bg, #fff);
  padding: 0;
  margin: 0;
  list-style: none;
  font-family: var(--cme-font-family, inherit);
  border-bottom: none !important;

  /* flex 基礎：會在桌機模式以 row 顯示（mobile 另處理） */
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-items: center;              /* 垂直置中 */
  justify-content: var(--cme-justify); /* 預設使用變數，Elementor 可直接覆寫 justify-content */
}

/* ---------- 第一層選單項目 ---------- */
.cme-megamenu > li {
  list-style: none;
  position: relative;

  flex: 0 0 auto; /* 保持項目依內容寬度而定，供 space-between 使用 */
}

/* 主選單連結 */
.cme-megamenu > li > a {
  display: block;
  padding: var(--cme-padding-vertical, 12px) var(--cme-padding-horizontal, 20px);
  text-decoration: none;
  color: var(--cme-link-color, #333);
  background-color: var(--cme-link-bg, transparent);
  transition: background 0.3s, color 0.3s;
  font-size: var(--cme-font-size, 16px);
  font-weight: var(--cme-font-weight, 400);
  text-transform: var(--cme-text-transform, none);
  border-radius: var(--cme-item-radius, 0);
}
.cme-megamenu > li > a:hover {
  background: var(--cme-hover-bg, #f5f5f5);
  color: var(--cme-hover-color, #000);
}

/* 子選單（下拉） */
.cme-megamenu .sub-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: var(--cme-submenu-bg, #fff);
  border: 1px solid var(--cme-submenu-border, #eee);
  box-shadow: 0 4px 10px rgba(0,0,0,0.05);
  z-index: 999;
  padding: var(--cme-submenu-padding, 0);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}
.cme-megamenu li:hover > .sub-menu {
  display: block;
  opacity: 1;
  visibility: visible;
}
.cme-megamenu .sub-menu li {
  list-style: none;
  border-bottom: 1px solid var(--cme-submenu-divider, #f0f0f0);
  position: relative;
}
.cme-megamenu .sub-menu li:last-child { border-bottom: none; }
.cme-megamenu .sub-menu li .sub-menu {
  top: 0;
  left: 100%;
  margin-left: 2px;
}

/* 子選單連結 */
.cme-megamenu .sub-menu li a {
  display: block;
  padding: var(--cme-submenu-item-padding-vertical, 10px) var(--cme-submenu-item-padding-horizontal, 16px);
  color: var(--cme-submenu-item-color, #444);
  background-color: var(--cme-submenu-item-bg, transparent);
  text-decoration: none;
  transition: background 0.3s, color 0.3s;
  font-size: var(--cme-submenu-font-size, 14px);
  font-weight: var(--cme-submenu-font-weight, 400);
  border-radius: var(--cme-submenu-item-radius, 0);
}
.cme-megamenu .sub-menu li a:hover {
  background: var(--cme-submenu-hover-bg, #f9f9f9);
  color: var(--cme-submenu-hover-color, #000);
}

/* 箭頭符號 */
.cme-megamenu li.menu-item-has-children > a::after {
  content: " ⌵";
  font-size: 1.2em;
  margin-left: 0.3em;
}
.cme-megamenu.no-submenu-arrows li.menu-item-has-children > a::after {
  content: none;
}









/* ---------- 第二層選單項目 ---------- */

/* ---------- 子選單圖片 / item flex 調整 ---------- */
.cme-sub-item { 
  display: flex; 
  align-items: center; 
  justify-content: flex-start; 
  flex-direction: row; 
}

.cme-sub-item.has-image {}

.cme-sub-image { 
  display: inline-flex; 
  align-items: center; 
  justify-content: center; 
  line-height: 0; 
}

.cme-sub-image img { 
  height: auto; 
  max-width: 100%; 
  object-fit: contain; 
  display: block; 
}

.cme-sub-label { 
  display: inline-block; 
  vertical-align: middle; 
}

.cme-sub-wrapper { 
  display: flex; 
  align-items: center; 
}

.cme-sub-image.cme-sub-pos-left { 
  margin-right: 8px; 
  order: -1; 
}
.cme-sub-image.cme-sub-pos-right { 
  margin-left: 8px; 
  order: 1; 
}
.cme-sub-wrapper.vertical { 
  flex-direction: column; 
  align-items: flex-start; 
}
.cme-sub-image.cme-sub-pos-top { 
  margin-bottom: 4px; 
  order: -1; 
}
.cme-sub-image.cme-sub-pos-bottom { 
  margin-top: 4px; 
  order: 1; 
}

/* 子選單 flex 方向 */
.cme-sub-pos-left   { flex-direction: row; }
.cme-sub-pos-right  { flex-direction: row-reverse; }
.cme-sub-pos-top    { flex-direction: column; }
.cme-sub-pos-bottom { flex-direction: column-reverse; }














/* ---------- 漢堡 / backdrop 等控制（桌機隱藏，手機再打開） ---------- */
.cme-hamburger, .cme-menu-close, .cme-menu-backdrop {
  display: none !important;
}



/* ---------- 手機 / 平板直式：漢堡 + overlay 側邊欄 ---------- */
@media (max-width: 1024px) and (orientation: portrait), (max-width: 767px) {
  /* 漢堡圖示（直式才顯示） */
  .cme-hamburger {
    display: flex !important;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
    width: 30px;
    height: 24px;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 0;
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 9999;
  }

  .cme-hamburger span {
    display: block;
    height: 3px;
    width: 100%;
    background: #333;
    border-radius: 2px;
    transition: transform .28s ease, opacity .28s ease;
  }

  /* 當選單打開時（wrapper 加上 .active）: 若你的需求是顯示 X 按鈕而隱藏漢堡，保留此行 */
  .cme-menu-wrapper.active .cme-hamburger {
    display: none !important;
  }
  /* 保險：避免 X 動畫殘留（若你另外使用 transform 轉 X，這一行可視情況移除） */
  .cme-menu-wrapper.active .cme-hamburger span {
    transform: none !important;
    opacity: 1 !important;
  }

  /* X 關閉按鈕（直式才顯示） */
  .cme-menu-close {
    display: block !important;
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10006;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    background: transparent;
    border: none;
  }

  /* 側邊選單 overlay（從左滑出） → 只在手機生效 */
.cme-megamenu {
  box-sizing: border-box;
  display: flex !important;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  width: 80%;
  max-width: 420px;
  height: 100vh;                   /* 直接控制高度 */
  background: var(--cme-bg, #fff);
  padding: 20px;
  z-index: 10004;
  overflow-y: auto;                /* 直向卷軸 */
  overflow-x: hidden;              /* 禁止橫向卷軸 */
  -webkit-overflow-scrolling: touch;
  transform: translateX(-100%);
  transition: transform .28s ease;
}
.cme-menu-wrapper.active .cme-megamenu {
  transform: translateX(0);
}


  /* 背景遮罩 */
  .cme-menu-backdrop {
    display: block !important;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 10002;
  }

  /* 手機子選單行為（直式） */
  .cme-megamenu .sub-menu {
    position: static;
    display: none;
    padding-left: 8px;
    margin: 0;
  }
  .cme-megamenu .menu-item-has-children.open > .sub-menu {
    display: block;
  }

  /* 手機選單項目外觀（直式） */
  .cme-megamenu > li > a {
    padding: var(--cme-mobile-padding-vertical, 6px) var(--cme-mobile-padding-horizontal, 10px);
    display: block;
  }

  .cme-megamenu > li {
    width: 100%;
  }
}

/* ---------- 確保水平選單位置能由 .cme-align-* 類別控制 ---------- */
.cme-align-left   .cme-megamenu { justify-content: flex-start !important; }
.cme-align-center .cme-megamenu { justify-content: center !important; }
.cme-align-right  .cme-megamenu { justify-content: flex-end !important; }
.cme-align-justify .cme-megamenu { justify-content: space-between !important; }


  /* 展開整個選單，再點關閉按鈕或 backdrop 收合 */
.cme-megamenu .menu-item-has-children.open > .sub-menu {
  display: block;
}




/* ---------- 選單內圖片 / item flex 調整（保留你的原本邏輯） ---------- */
.cme-menu-item { display: flex; align-items: center; justify-content: flex-start; flex-direction: row; }
.cme-menu-item.has-image {}
.cme-item-image { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.cme-item-image img { height: auto; max-width: 100%; object-fit: contain; display: block; }
.cme-item-label { display: inline-block; vertical-align: middle; }
.cme-item-wrapper { display: flex; align-items: center; }
.cme-item-image.cme-pos-left { margin-right: 8px; order: -1; }
.cme-item-image.cme-pos-right { margin-left: 8px; order: 1; }
.cme-item-wrapper.vertical { flex-direction: column; align-items: flex-start; }
.cme-item-image.cme-pos-top { margin-bottom: 4px; order: -1; }
.cme-item-image.cme-pos-bottom { margin-top: 4px; order: 1; }
.cme-flex { display: flex; align-items: center; }
.cme-pos-left { flex-direction: row; }
.cme-pos-right { flex-direction: row-reverse; }
.cme-pos-top { flex-direction: column; }
.cme-pos-bottom { flex-direction: column-reverse; }
.cme-menu-wrapper .cme-menu-item.cme-flex { display: inline-flex; align-items: center; }
.cme-menu-wrapper .cme-menu-item.cme-flex.cme-pos-left   { flex-direction: row; }
.cme-menu-wrapper .cme-menu-item.cme-flex.cme-pos-right  { flex-direction: row-reverse; }
.cme-menu-wrapper .cme-menu-item.cme-flex.cme-pos-top    { flex-direction: column; }
.cme-menu-wrapper .cme-menu-item.cme-flex.cme-pos-bottom { flex-direction: column-reverse; }
.cme-menu-wrapper .cme-item-image img { display: block; height: auto; max-width: 100%; }


.cme-align-left .cme-megamenu {
  display: flex;
  justify-content: flex-start;
}
.cme-align-center .cme-megamenu {
  display: flex;
  justify-content: center;
}
.cme-align-right .cme-megamenu {
  display: flex;
  justify-content: flex-end;
}
.cme-align-justify .cme-megamenu {
  display: flex;
  justify-content: space-between;
}

