:root {
  /* 顏色變數 */
  --blue-main: #3b82f6;
  --blue-soft: #5c9ded;
  --blue-lite: #eaf4ff;
  --text: #0b2447;
  --white: #ffffff;
  --dark-overlay: rgba(0, 0, 0, 0.08);

  /* 尺寸變數 */
  --sidebar-w: 250px;
  --sidebar-coll-w: 64px;
  --header-h: 64px;
  --footer-h-expanded: 210px;
  --footer-h-collapsed: 56px;

  /* 間距變數 (統一化) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 20px;

  /* 圓角變數 (統一化) */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-full: 999px;

  /* 陰影變數 (統一化) */
  --shadow-sm: 0 1px 3px rgba(2, 6, 23, 0.08);
  --shadow-lg: 0 8px 24px rgba(2, 6, 23, 0.12);
}

/* 基本 */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html, body {
    min-height: 100%;
    font: 100%/1.5 Inter, Arial, sans-serif;
    background-color: var(--blue-lite);
    color: var(--text);
}
a {
    text-decoration: none;
    color: inherit;
    outline-color: var(--blue-main);
}
button {
    cursor: pointer;
    border: none;
    background: transparent;
}
/* 螢幕閱讀器專用 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
/* 替換原本 HTML 中的 inline style */
.content-placeholder {
  min-height: 1400px;
  background: linear-gradient(180deg, var(--white), var(--blue-lite));
  border-radius: var(--radius-md);
  padding: var(--space-lg);
}


/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-w);

    background: var(--blue-main);
    color: var(--white);

    display: flex;
    flex-direction: column;
    padding: var(--space-md);
    gap: var(--space-md);

    /* ✅ 關鍵修正：啟用 GPU 硬體加速 */
    transform: translate3d(0, 0, 0);

    transition: width 0.28s ease;
    overflow-y: auto;
    z-index: 60;
    box-shadow: var(--shadow-lg);
}
.sidebar.collapsed {
    width: var(--sidebar-coll-w);
    align-items: center;
    padding-left: var(--space-xs);
    padding-right: var(--space-xs);
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    width: 100%;
}
.brand img {
    width: 38px;
    height: 38px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}
.brand .brand-text {
    font-weight: 700;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar.collapsed .brand {
    justify-content: center;
    padding: var(--space-md) 0;
}
.sidebar.collapsed .brand .brand-text {
    display: none;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
    padding-top: var(--space-xs);
    width: 100%;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm);
    border-radius: var(--radius-md);
    color: var(--white);
    transition: background 0.12s;
    white-space: nowrap;
    position: relative;
    justify-content: flex-start;
}
.nav-link i {
    width: 26px;
    text-align: center;
    font-size: 16px;
}
.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: var(--space-sm);
}
.nav-link .label {
    font-size: 14px;
}
.sidebar.collapsed .nav-link .label {
    display: none;
}
.nav-link:hover,
.nav-link:focus {
    background: var(--dark-overlay);
    outline: none;
}
.nav-link.active {
    background: var(--blue-soft);
    font-weight: 600;
}

/* --- Tooltip --- */
.tooltip {
    position: fixed;
    left: calc(var(--sidebar-coll-w) + var(--space-md));
    background: var(--blue-main);
    color: var(--white);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    transform: translateX(-20px) scale(0.8);
    transition: transform 0.25s ease-out, opacity 0.25s ease-out;
    font-weight: 700;
    font-size: 14px;
    white-space: nowrap;
}
.tooltip.show {
    transform: translateX(0) scale(1);
    opacity: 1;
}

/* --- Header --- */
.header {
    position: fixed;
    top: 0;
    left: var(--sidebar-w);
    right: 0;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    background: var(--blue-soft);
    color: var(--white);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    transition: left 0.28s ease;
}
body.sidebar-collapsed .header {
    left: var(--sidebar-coll-w);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}
.header-left img {
    width: 38px;
    height: 38px;
    object-fit: contain;
    border-radius: var(--radius-sm);
}
.header-left .title {
    font-weight: 700;
    font-size: 18px;
}
.menu-toggle {
    display: none;
    color: var(--white);
    padding: var(--space-sm);
    font-size: 18px;
    line-height: 0;
}

.header-center {
    display: flex;
    gap: var(--space-sm);
    flex: 1;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    padding: 0 var(--space-md);
}
.category {
    background: var(--white);
    color: var(--blue-main);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.1s;
}
.category:hover {
    background: var(--blue-lite);
    color: var(--blue-soft);
}
.category.highlight {
    background: #ffcc00;
}

.header-right {
    display: flex;
    gap: var(--space-md);
    align-items: center;
}

/* Search */
.search {
    position: relative;
    min-width: 200px;
}
.search input {
    padding: var(--space-sm) 36px var(--space-sm) var(--space-md);
    border-radius: var(--radius-full);
    border: 1px solid rgba(255, 255, 255, 0.4);
    outline: none;
    width: 100%;
    color: var(--text);
}
.search button {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);

    background: var(--blue-main);
    color: var(--white);
    padding: 5px 9px;
    border-radius: var(--radius-full);
    line-height: 0;
}
.search button i {
    font-size: 16px;
}

/* Header Buttons & Dropdowns */
.header-btn {
    position: relative;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    color: var(--white);
    font-size: 14px;
    font-weight: 500;
    transition: background 0.12s;
}
.header-btn:hover,
.header-btn:focus,
.header-btn.active {
    background: var(--dark-overlay);
    outline: none;
}
.header-btn i {
    margin-right: var(--space-xs);
}

.header-btn .dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 140px;
    background: var(--white);
    box-shadow: var(--shadow-sm);
    border-radius: var(--radius-md);
    padding: var(--space-sm) 0;
    margin-top: var(--space-xs);

    display: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, transform 0.2s;
    transform: translateY(-10px);
    z-index: 100;
}
.header-btn.active .dropdown {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.header-btn .dropdown a {
    display: block;
    padding: var(--space-sm) var(--space-md);
    color: var(--text);
}
.header-btn .dropdown a:hover {
    background: var(--blue-lite);
    color: var(--blue-main);
}

/* --- Main Content Wrapper --- */
.main-wrap {
    padding-top: var(--header-h);
    padding-left: var(--sidebar-w);
    transition: padding-left 0.28s ease, padding-top 0.28s ease;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}
body.sidebar-collapsed .main-wrap {
    padding-left: var(--sidebar-coll-w);
}

/* Main */
.main {
    flex-grow: 1;
    padding: var(--space-lg);
    /* 底部間距由 JS 動態設置，以避開 Footer */
    transition: padding-bottom 0.28s ease;
}
.page-header {
  margin-bottom: var(--space-lg);
}
.page-header h2 {
  font-size: 24px;
  color: var(--text);
}
.page-header .subtitle {
  color: #64748b;
  margin-top: var(--space-xs);
}


/* --- Footer --- */
#footer {
  background: var(--blue-soft);
  box-shadow: var(--shadow-sm);
  color: var(--white);

  /* 【GPU 加速】：消除動畫誤差 */
  transform: translate3d(0, 0, 0);

  position: fixed;
  bottom: 0;
  right: 0;
  height: var(--footer-h-expanded);

  /* 【關鍵修正】：強制全螢幕寬度，徹底消除縫隙 */
  left: 0;
  transform: none;
  overflow: hidden;

  z-index: 40;
  transition: height 0.28s ease, left 0.28s ease;

  display: flex;
  flex-direction: column;
}

/* 【內容平移】：使用 transform 避開 Sidebar 空間 */
  transform: translateX(var(--sidebar-w));

  /* 確保內容區的寬度 = 螢幕寬度 - Sidebar 寬度 */
  width: calc(100% - var(--sidebar-w));

  /* 【高度修正】：清除可能導致截斷的最小高度限制 */
  min-height: auto;

  overflow: hidden;
  transition: transform 0.28s ease, width 0.28s ease;
}

/* Sidebar 收合時 */
body.sidebar-collapsed #footer .footer-inner {
    transform: translateX(var(--sidebar-coll-w));
    width: calc(100% - var(--sidebar-coll-w));
}

/* --- Footer 內容區塊修正 --- */
#footer .footer-inner {
  flex-grow: 1;
  display: flex;
  justify-content: space-between;
  padding: var(--space-lg);
  margin: 0 auto;
  flex-wrap: wrap;

  /* 寬度由 left/right 決定，這裡只確保內部的 flex 佈局 */
  width: 100%;
  margin-right: 0;
  overflow: hidden;
}

/* Footer 內容圖示修正 (防止圖示擠壓版面) */
#footer i {
    font-size: 16px;
    line-height: 1;
    display: inline-block;
    width: auto;
    height: auto;
}
.footer-col a i {
    margin-right: 6px;
}

/* Footer 欄位 (修正擠壓為單行) */
.footer-col {
  /* 略微縮小基礎寬度，釋放空間 */
  flex-basis: 20%;
  /* 【關鍵修正】：降低最小寬度，以確保四欄可以並排 */
  min-width: 110px;
  margin-bottom: var(--space-md);
  text-align: center;
}
.footer-col h4 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: var(--space-md);
  color: var(--white);
}
.footer-col a, .footer-col p {
  display: block;
  font-size: 14px;
  color: var(--white);
  margin-bottom: var(--space-sm);
}
.footer-col a:hover {
  text-decoration: underline;
  color: var(--blue-lite);
}

/* Footer 工具列和按鈕樣式 */
.footer-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: var(--space-sm);

}


/* 版權區塊樣式 */
.copyright {
  text-align: center;
  padding-bottom: var(--space-md);
  padding-top: var(--space-xs);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
}
.copyright p {
  font-size: 12px;
  color: var(--blue-lite);
}

/* --- 收合狀態的關鍵修正 --- */

/* Footer 收合時的樣式 */
#footer.collapsed {
    height: var(--footer-h-collapsed);
    overflow: hidden;
    position: relative;
}
#footer.collapsed .footer-inner {
    display: none; /* 隱藏主要內容欄位 */
}
#footer.collapsed .copyright {
    display: none; /* 隱藏版權資訊，避免與按鈕重疊 */
}

/* 確保在收合狀態下，工具列和按鈕顯示在中間 */
#footer.collapsed .footer-toolbar {
    display: flex;
    justify-content: center;
    align-items: center;
    height: var(--footer-h-collapsed);
    width: 100%;
    position: absolute;
    top: 0;
    padding: 0;
}

/* --- Media Queries --- */
/* ... (所有 Footer、Main Content、Toolbar, Copyright, 等等樣式) ... */


/* --- 行動裝置專用 Overlay 類別 (放在 Media Query 外) --- */

/* 讓 Sidebar 顯示出來的樣式 */
body.mobile-sidebar-open .sidebar {
    left: 0; /* 讓 Sidebar 彈出 */
    box-shadow: var(--shadow-lg); /* 彈出時加上陰影 */
}

/* 確保 Header 和 Main 不會因為 Sidebar 彈出而被擠壓 */
body.mobile-sidebar-open .header {
    left: 0; /* 保持 Header 位置不變 */
}
body.mobile-sidebar-open .main-wrap {
    padding-left: 0; /* 保持 Main Content 位置不變 */
}

/* --- Media Queries --- */
@media (max-width: 768px) {

    /* ... (Media Query 內部的 Sidebar 隱藏、Header/Main 調整等樣式) ... */

}
@media (max-width: 1200px) {
  /* 針對 Header 進行調整 */
  .header-center {
    display: none; /* 隱藏分類標籤 */
  }
}

@media (max-width: 992px) {
  /* 針對 Footer 進行調整 */
  .footer-inner {
    justify-content: center;
  }
  .footer-col {
    /* 在較小的螢幕上改為兩欄佈局 */
    flex-basis: 40%;
    min-width: 200px;
  }
}

/* --- Media Queries --- */
@media (max-width: 768px) {

    /* 1. 預設隱藏 Sidebar */
    .sidebar {
        left: calc(0px - var(--sidebar-w)); /* 將 Sidebar 藏到螢幕左邊 */
        transition: left 0.28s ease;
        box-shadow: none;
    }

    /* 2. 移除 Sidebar 的收合樣式，在行動裝置上只處理隱藏/顯示 */
    .sidebar.collapsed {
        width: var(--sidebar-w); /* 保持寬度，但藏起來 */
    }

    /* 3. 確保 Header 和 Main 內容佔滿整個螢幕 */
    .header {
        left: 0; /* Header 從最左邊開始 */
    }
    .main-wrap {
        padding-left: 0; /* Main Content 從最左邊開始 */
    }
    body.sidebar-collapsed .header {
        left: 0;
    }
    body.sidebar-collapsed .main-wrap {
        padding-left: 0;
    }

    /* 4. 顯示菜單按鈕 */
    .menu-toggle {
        display: block;
    }

    /* 5. Footer 也應該佔滿整個螢幕，避免與 Sidebar 衝突 */
    #footer {
        left: 0 !important; /* 強制覆蓋之前的所有 left 設置 */
    }
}

/* 強制讓下拉選單在滑鼠移入時顯示 */
.header-admin {
    position: relative !important;
}

.header-admin:hover .dropdown {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    min-width: 150px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    z-index: 99999; /* 確保它在最前面 */
}

.dropdown a {
    display: block !important;
    padding: 10px 15px !important;
    color: #333 !important;
    text-decoration: none !important;
}

.dropdown a:hover {
    background-color: #f0f0f0 !important;
}
