/* =========================================
   1. 核心變數 (Variables)
   ========================================= */
:root {
  /* --- 桌機版參數 (Desktop) --- */
  --unified-rail: min(360px, 32vw);
  --top-offset: 64px;
  --gap: 12px;
  --panel-resize-handle-width: 8px;
  --radius-card: 16px;
  --dropdown-allowance: 230px;

  /* --- 平板/手機版參數 (Tablet/Mobile) --- */
  --editor-h: 72px;
  --sheet-gap: 0px;
  --sheet-h: calc(100vh - var(--editor-h) - 50px);
}

#MobileTabs {
  display: none;
}

/* QA 手風琴樣式 */
.unified-panel .qa-item {
  /* border-radius: 12px; */
  overflow: hidden;
  background: #fff;
  border-bottom: 1px dotted #82bf25;
}

.unified-panel .qa-q {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #ffffff;
  color: #000000;
  cursor: pointer;
}

.unified-panel .qa-q .arrow {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  transition: transform .2s ease;
}

.unified-panel .qa-q .arrow::before {
  content: "⌄";
  font-size: 1.14rem;
  line-height: 1;
  margin-top: -4px;
  color: #000;
}

.unified-panel .qa-item.open .qa-q .arrow {
  transform: rotate(180deg);
}

.unified-panel .qa-a {
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease;
  background: #fff;
}

.unified-panel .qa-item.open .qa-a {
  max-height: 600px;
}

.unified-panel .qa-btn-list {
  padding: 10px;
}

.unified-panel .qa-btn {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  margin: 4px 0;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  color: #111827;
  cursor: pointer;
}

.unified-panel .qa-btn:hover {
  background: #f9fafb;
}

/* 側邊欄連結項目 */
.unified-panel .sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .2s;
}

.unified-panel .sidebar-item:hover {
  background: #f3f4f6;
}

.unified-panel .sidebar-icon {
  font-size: 1.28rem;
}

/* 內容切換邏輯 (通用) */
.unified-panel .panel-content {
  display: none;
  height: 100%;
  overflow: auto;
  flex-direction: column;
  /* padding-top: 4px; */
}

body.unified-open.show-brand .unified-panel .brand-content {
  display: flex;
}

body.unified-open.show-integrated .unified-panel .integrated-content {
  display: flex;
}


/* =========================================
   3. 桌機版 (Desktop Styles - Default)
   說明: 預設為桌機樣式，不設 min-width
   ========================================= */

.unified-panel {
  position: fixed !important;
  top: var(--top-offset) !important;
  right: var(--gap) !important;
  height: calc(100vh - var(--top-offset) - var(--gap)) !important;
  width: var(--unified-rail) !important;
  transform: translateX(120%);
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), top 0.3s ease, height 0.3s ease;
  z-index: 1000;
  border: 1px solid #e5e7eb !important;
  border-radius: var(--radius-card);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .08) !important;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.unified-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  z-index: 4;
  pointer-events: none;
}

body.unified-open .unified-panel {
  transform: translateX(0);
}

#dvP4Page input{
    border: 1px solid #000000 !important;
}

@media (min-width: 1025px) {

  /* 漢堡選單避讓 */
  body.dropdown-open .unified-panel {
    top: calc(var(--top-offset) + var(--dropdown-allowance)) !important;
    height: calc(100vh - var(--top-offset) - var(--dropdown-allowance) - var(--gap)) !important;
  }

  body.unified-open #ChatZone {
    right: calc(var(--unified-rail) + var(--gap) + var(--gap)) !important;
    width: auto !important;
    transition: right 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  }
  body.unified-open #dvP4Page {
    right: calc(var(--unified-rail) + var(--gap) + var(--gap)) !important;
    left: var(--gap) !important;
    width: auto !important;
    transition: right 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  }
}

body.unified-open #dropdown-menu,
body.unified-open #fontsize-dropdown-menu {
  right: var(--gap) !important;
  width: var(--unified-rail) !important;
  max-width: var(--unified-rail) !important;
  /* transition: right 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); */
}

body.panel-resizing .unified-panel,
body.panel-resizing #LeftZone {
  transition: none !important;
}

.unified-panel .sidebar-header {
  padding: 20px 20px 16px 20px;
  /* border-bottom: 1px solid #f3f4f6; */
  background: #fff;
  height: 48px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  justify-content: space-between;
}

.unified-panel .sidebar-header h3 {
  align-items: center;
  margin: 0;
  display: inline-flex;
  font-weight: 600;
  font-size: 1.28rem;
  height: 30px;
  justify-content: center;
  width: 30px;
  color: #111827;
}

.unified-panel .sidebar-header .panel-title-icon i {
  font-size: 1.25rem;
  line-height: 1;
}

.unified-panel .sidebar-header .panel-title-logo {
  display: block;
  height: 100%;
  object-fit: contain;
  width: auto;
}

.unified-panel .sidebar-header .sr-only-text {
  border: 0;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.unified-panel .sidebar-body {
  padding: 20px;
  background: #fff;
  overflow-y: auto;
  flex-grow: 1;
}

.desktop-panel-tabs {
  margin-top: 2rem;
  margin-right: -5px;
  transform: translateY(-50%);
  z-index: 1100;
  display: none;
  gap: 6px;
}

body.unified-open .desktop-panel-tabs {
  display: flex;
}

.desktop-panel-tabs button {
  border: 1px solid #d1d5db;
  background: rgba(255, 255, 255, 0.9);
  color: #374151;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.desktop-panel-tabs button:hover {
  background: #fff;
  border-color: #9ca3af;
  transform: translateY(-1px);
}

.desktop-panel-tabs button.active {
  background: #82bf25;
  color: #fff;
  border-color: #82bf25;
  box-shadow: 0 4px 12px rgba(130, 191, 37, 0.3);
}

.panel-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--panel-resize-handle-width);
  cursor: col-resize;
  background: transparent;
  z-index: 10;
}

.panel-resize-handle:hover {
  background: rgba(130, 191, 37, 0.3);
}

.sidebar-item {
  flex: 1 1 calc(50% - 10px);
  max-width: calc(50%);
  padding: 40px 5px !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 5px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  color: #222831;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  text-align: center;
  min-height: 55px;
  min-width: 60px;
}


.sidebar-body {
  flex: 1;
  padding: 15px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
}

.sidebar-icon {
  margin-right: 0;
  margin-bottom: 3px;
  width: auto;
  text-align: center;
  font-size: 2.86rem !important;
}


/* =========================================
   4. 平板版 (Tablet Styles)
   條件: max-width: 1024px
   ========================================= */
@media (max-width: 1024px) {
  #sidebar-menu-btn {
    display: none !important;
  }

  .unified-panel .sidebar-header,
  .unified-panel .desktop-panel-tabs,
  .panel-resize-handle {
    display: none !important;
  }

  /* 內容切換邏輯 (通用) */
  .unified-panel .panel-content {
    display: none;
    height: 100%;
    overflow: auto;
    padding-top: 4px;
  }

  .unified-panel .qa-item {
    width: calc(100vw - 56px);
  }

  body.unified-open.show-brand .unified-panel .brand-content {
    display: block;
  }

  /* 分頁列容器 */
  .mobile-tabs {
    display: flex !important;
    position: sticky;
    top: 0;
   /*  z-index: 1100; */
    /* background: #ffffff; */
    background: transparent;
    /* box-shadow: #d1d1d1 2px 2px 4px; */
    /* border-bottom: 1px solid #e5e7eb; */
    height: 50px;
    /* width: 100%;  */
    padding: 5px;
    margin: 0 8px;
    border-radius: 1rem;
  }

  /* 單個分頁按鈕 (置中修正) */
  .mobile-tabs .mtab {
    flex: 1;
    flex-basis: 0;
    min-width: 0;

    display: flex;
    align-items: center;
    justify-content: center;
    /* 置中 */

    padding: 0 4px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #475569;
    font-weight: 600;
    font-size: 1rem;
    gap: 6px;
    position: relative;
    white-space: nowrap;
  }

  .mobile-tabs .mtab[aria-selected="true"] {
    color: #FFFFFF;
    background: #01a93c;
    border-radius: 1rem;
    /* transition: left 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), background-color 0.3s ease; */
    font-weight: bolder;
  }

  .mobile-tabs .mtab-indicator {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    width: 33.333%;
    /* background: #0099FF; */
    transition: left .25s ease;
    pointer-events: none;
  }

  /* 聊天區顯示控制 (回復到原本的單純切換，不強制定位) */
  body.mtab-chat #ChatZone {
    display: block !important;
    top: 102px;
  }

  body.mtab-faq #ChatZone,
  body.mtab-links #ChatZone {
    display: none !important;
  }

  /* 面板容器 (Bottom Sheet) */
  .unified-panel {
    position: fixed !important;
    left: 0;
    right: 0;
    top: 50px !important;
    bottom: calc(var(--editor-h) + var(--sheet-gap));
    width: calc(100% - 24px) !important;
    height: var(--sheet-h) !important;
    transform: translateY(110%);

    /* 修正：移除手機版滑動動畫，瞬間切換 */
    transition: none !important;

    z-index: 1001;
    background: #fff;
    display: flex;
    flex-direction: column;
    border: none !important;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, .1) !important;
  }

  body.unified-open .unified-panel {
    transform: translateY(0);
    margin: 0 12px;
    margin-top: 52px;
  }

  body.unified-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  .unified-panel .panel-content {
    flex: 1;
  }

  .unified-panel .sidebar-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: 80px;
  }

  .unified-panel .sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
  }

  .unified-panel .sidebar-item .sidebar-icon {
    font-size: 1.28rem;
    text-align: center;
  }

  .sidebar-item {
    flex: 1 1 calc(33.333% - 8px);
    max-width: calc(33.333% - 8px);
  }

  .unified-panel .qa-q {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: #0d5fa5;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
  }
}


/* =========================================
   5. 手機版 (Mobile Styles)
   條件: max-width: 768px
   ========================================= */
@media (max-width: 768px) {
  .unified-panel .sidebar-body {
    padding: 12px;
  }

  .sidebar-item {
    flex: 1 1 calc(25% - 10px);
    max-width: calc(25% - 10px);
  }
}


/* =========================================
   6. 保留區塊 (Special Overrides)
   ========================================= */
@media (max-width: 1100px) {
  .unified-panel .sidebar-header h3 {
    font-size: 1.125rem;
  }

  .desktop-panel-tabs button {
    font-size: 0.58rem;
  }
}

/* =========================================
   7. 縮放時禁止動畫 (鬼影防禦)
   ========================================= */
body.resize-active,
body.resize-active * {
  transition: none !important;
  animation: none !important;
}

body.resize-active:not(.unified-open) .unified-panel {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
}


/* 修改常見問題頁：不要用 flex 排版，改回一般直向排列 */
.unified-panel .brand-content .sidebar-body {
  display: block;
  padding: 20px;
}

/* 常見問題每一項都撐滿 */
.unified-panel .brand-content .qa-list,
.unified-panel .brand-content .qa-item {
  width: 100%;
  box-sizing: border-box;
}

/* 藍色標題列撐滿 */
.unified-panel .brand-content .qa-q {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
}

/* 文字區撐開，箭頭固定在右邊 */
.unified-panel .brand-content .q-text {
  flex: 1 1 auto;
  min-width: 0;
}

.unified-panel .brand-content .arrow {
  flex-shrink: 0;
  margin-left: 12px;
}

/* 熱門連結頁才維持 flex 格狀 */
.unified-panel .integrated-content .sidebar-body {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
}

/* ==========================================================================
   客製化調整：熱門連結區塊重構為雙欄垂直列表 (重置原本的卡片格狀樣式)
   ========================================================================== */

/* 1. 覆寫熱門連結的側邊欄容器，由原本的 Flex 格狀改為 Block 順向排列 */
#AI3-WebChat .unified-panel .integrated-content .sidebar-body {
  display: block !important;
  padding: 15px !important;
}

/* 2. 主容器：改為上下垂直排列 (Column) */
#AI3-WebChat .hot-links-wrapper {
  display: flex !important;
  flex-direction: column !important;       /* ★ 上下堆疊 */
  justify-content: flex-start !important;
  gap: 16px !important;                    /* 區塊之間的間距 */
  width: 100% !important;
  box-sizing: border-box !important;
}

/* 3. 獨立的白色分類框：讓它橫向撐滿 */
#AI3-WebChat .links-column-box {
  width: 100% !important;                  /* ★ 橫向撐滿 */
  flex: none !important;
  border: 1px solid #e5e7eb !important;
  border-radius: 8px !important;
  padding: 16px !important;
  background-color: #ffffff !important;
  box-sizing: border-box !important;
}

/* 4. 欄位大標題樣式 */
#AI3-WebChat .column-box-title {
  font-size: 1.05rem !important;
  font-weight: bold !important;
  color: #111827 !important;
  margin-bottom: 12px !important;
  text-align: left !important;
}

/* 清除 ul 預設樣式 */
#AI3-WebChat .column-links-list {
  list-style: none !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* 5. 強制重設 .sidebar-item 樣式：還原為乾淨的「橫向列表行」 */
#AI3-WebChat .hot-links-wrapper .sidebar-item {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-start !important;
  flex: none !important;
  max-width: none !important;
  width: 100% !important;
  min-height: 0 !important;
  min-width: 0 !important;
  padding: 10px 0 !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  margin-bottom: 0 !important;
  text-align: left !important;
}

/* 6. 覆寫原本放大到 2.86rem 的大圖示，縮小回符合小列表的比例 */
#AI3-WebChat .hot-links-wrapper .sidebar-icon {
  font-size: 1.25rem !important;
  margin-right: 14px !important;           /* 確保圖文有間距 */
  margin-bottom: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
}

/* 7. 列表行文字樣式與懸停變色效果 */
#AI3-WebChat .hot-links-wrapper .link-text-label {
  font-size: 1.4rem !important;
  color: #374151 !important;
  font-weight: 500 !important;
  white-space: nowrap !important;          /* ★ 強制文字不換行，保持單行乾淨顯示 */
  transition: color 0.2s ease !important;
}

#AI3-WebChat .hot-links-wrapper .sidebar-item:hover .link-text-label {
  color: #0d5fa5 !important;
}
