/* =========================================
   1. 變數與基礎設定
   ========================================= */
:root {
  --sidebar-btn-color: #444746;
  --sidebar-btn-bg-hover: rgba(68, 71, 70, 0.08);
  --sidebar-btn-focus-ring: #0b57d0;
}

/* =========================================
   2. 欄位基礎過渡與狀態
   ========================================= */
.row_0 .col_01 {
  /* 加上明確的初始寬度，讓瀏覽器有數值可以計算過渡動畫 */
  max-width: 20%; 
  min-width: 20%; 
  will-change: max-width, min-width, padding, margin;
  overflow: hidden; 
  white-space: nowrap; 
  /* 移除預設的 transition，交由下方的 .is-sidebar-toggling 控制，避免與滾動事件衝突 */
}

.row_0 .col_02 {
  /* 移除預設的 transition */
}

/* 只有在點擊按鈕的 0.3 秒內，才賦予過渡動畫，避免與滾動事件衝突 */
.row_0.is-sidebar-toggling .col_01 {
  transition: max-width 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.3s ease, margin 0.3s ease, opacity 0.2s ease;
}

.row_0.is-sidebar-toggling .col_02 {
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              padding-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.row_0 .col_01.is-collapsed {
  max-width: 0 !important;
  min-width: 0 !important;
  padding-inline: 0 !important;
  margin-inline: 0 !important;
  opacity: 0 !important;
  border: none !important;
}

/* =========================================
   3. 零體積按鈕容器與按鈕本體
   ========================================= */
#custom-sidebar-toggle-wrapper {
  position: sticky;
  top: 16px; 
  width: 0;
  height: 0; 
  z-index: 100;
  overflow: visible;
}

#custom-sidebar-toggle {
  position: absolute;
  top: 0;
  left: -1em; /* 展開時的預設位置 */
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: transparent;
  color: var(--sidebar-btn-color);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#custom-sidebar-toggle:hover,
#custom-sidebar-toggle:focus-visible {
  background-color: var(--sidebar-btn-bg-hover); 
  outline: none;
}

#custom-sidebar-toggle:focus-visible {
  border: 2px solid var(--sidebar-btn-focus-ring);
}

#custom-sidebar-toggle svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* =========================================
   4. 響應式佈局與收闔狀態修正
   ========================================= */
@media (min-width: 1024px) {
  /* 當側邊欄收合時，為 .col_02 整體增加內距，騰出按鈕空間 */
  .row_0:has(.col_01.is-collapsed) .col_02 {
    padding-left: 56px; 
    width: 100%;
  }

  /* 抵銷 .col_02 內距造成的位移，將按鈕固定在視窗邊緣 */
  .row_0:has(.col_01.is-collapsed) #custom-sidebar-toggle {
    left: -48px; 
  }
}