/* ==========================================================================
   common.css - Shared Sidebar/Header styles (Final Integrated Version)
   Contains: Layout, Theme Variables, Mobile Fixes, Collapsed Mode Logic
   ========================================================================== */

/* =========================================
   1. 定義變數 (CSS Variables)
   ========================================= */

/* === 預設：淺色模式 (Light Mode) === */
:root {
  /* --- 🎨 顏色設定 --- */
  --bg-primary: #FDF9F0;       /* 大背景 */
  --bg-secondary: #FEFDFB;     /* Sidebar 背景 */
  --bg-card: #FFFFFF;          /* 卡片/按鈕背景 */
  --bg-hover: #E8F2ED;         /* Hover */
  --bg-active: #CDE8DE;        /* Active */
  --bg-input: #FFFFFF;         /* 輸入框 */

  /* 邊框 */
  --border: #E8DCC8;
  --border-sub: rgba(0,0,0,0.08);

  /* 文字與主色 */
  --primary: #1a3d2e;          /* 主色 (深綠) */
  --primary-light: #2D5F3F;    /* 輔色 */
  --accent: #2D5F3F;           /* 強調色 */
  
  --text-primary: #1a3d2e;     /* 主要文字 */
  --text-secondary: #4F8A60;   /* 次要文字 */
  --text-muted: #7BA888;       /* 提示字 */
  --text-on-dark: #FFFFFF;

  /* 特殊 */
  --shadow-color: rgba(26, 61, 46, 0.05);
  --progress-track: #e2e8f0;

  /* --- 📐 排版變數 (Layout) --- */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 72px;
  --header-height: 60px;

  --lex-gold: #c5a059;

  /* --- 📢 通知欄專用變數 (Notification) --- */
  /* 在淺色模式下，通知欄用「主色深綠」做底，白字金邊，突出顯示 */
  --notify-bg: #1a3d2e;       
  --notify-text: #FFFFFF;     
  --notify-link: #c5a059;     
  --notify-border: #c5a059;   
}

/* === 深色模式 (Dark Mode) === */
[data-theme="dark"] {
  --bg-primary: #111827;       /* 大背景 (深藍黑) */
  --bg-secondary: #1f2937;     /* Sidebar (稍淺黑) */
  --bg-card: #374151;          /* 卡片 (深灰) */
  --bg-hover: #4b5563;         /* Hover (灰) */
  --bg-active: #374151;        /* Active */
  --bg-input: #374151;

  --border: #374151;
  --border-sub: rgba(255,255,255,0.1);

  --primary: #A47523;          /* 主色變亮 (金) */
  --primary-light: #CFA24E;
  --accent: #CFAF7E;

  --text-primary: #f9fafb;     /* 主要文字 (白) */
  --text-secondary: #d1d5db;   /* 次要文字 (淺灰) */
  --text-muted: #9ca3af;       /* 暗灰 */
  --text-on-dark: #FFFFFF;

  --shadow-color: rgba(0, 0, 0, 0.3);
  --progress-track: #4b5563;

  --lex-dark: #1a1c1e;

  /* --- 📢 通知欄專用變數 (Dark Mode) --- */
  /* 深色模式下，通知欄用「次要背景」做底，避免太刺眼 */
  --notify-bg: #1f2937;       
  --notify-text: #f9fafb;     
  --notify-link: #CFA24E;     
  --notify-border: #4b5563;   
}

:root {
    --sidebar-width: 260px;      /* 展開時的寬度 */
    --sidebar-collapsed-width: 72px; /* 收縮時的寬度 */
    --notify-height: 46px;       /* 通知欄的高度 (大約值，用於計算下移距離) */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* ★★★ 全局設定：Body 設為 relative，並禁止整體捲動 ★★★ */
html, body {
  min-height: 100%;
  margin: 0;
  overflow: hidden; /* ★ 關鍵：禁止整個網頁捲動 */
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    position: relative;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body.collapsed-mode {
    --sidebar-width: var(--sidebar-collapsed-width);
}

/* =========================================
   2. Fixed Header (Left)
   ========================================= */
.fixed-header-left {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 15px;
  z-index: 2000;
  background-color: var(--bg-secondary);
  border-bottom: none !important;
  transition: width 0.3s ease, background-color 0.3s ease;
}

body.collapsed-mode .fixed-header-left {
  width: var(--sidebar-collapsed-width);
  padding: 0 20px !important;
  justify-content: flex-start !important;
  background-color: var(--bg-secondary) !important;
}

.hamburger-btn {
  background: none; border: none; cursor: pointer; padding: 8px;
  color: var(--text-primary);
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; width: 40px; height: 40px;
  transition: background 0.2s; flex-shrink: 0;
}
.hamburger-btn:hover { background-color: var(--bg-hover); }

.logo-area { cursor: pointer; display: flex; align-items: center; }
.logo-image { height: 84px; width: auto; display: block; }

/* Logo 切換邏輯 */
.logo-light { display: block; }
.logo-dark { display: none; }
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark { display: block; }

body.collapsed-mode .logo-area { display: flex !important; opacity: 1 !important; }
body.collapsed-mode .logo-image { height: 84px; width: auto; }
body.collapsed-mode .hamburger-btn { margin: 0 !important; }

/* =========================================
   3. Sidebar (Base Layout)
   ========================================= */
/* 注意：這是基礎樣式，底部的「終極修正」會覆蓋部分屬性以確保穩定性 */
.sidebar {
  position: fixed;
  top: 60px; left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  background-color: var(--bg-secondary);
  border-right: none !important;
  display: flex; flex-direction: column;
  padding: 10px 15px 20px;
  z-index: 1000;
  transition: width 0.3s ease, background-color 0.3s ease;
  overflow-y: auto; overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.1); border-radius: 4px; }
.sidebar:hover::-webkit-scrollbar-thumb { background-color: rgba(0,0,0,0.2); }

/* Transition Setting */
.sidebar, .fixed-header-left, .chat-page-container, .chat-main, .logo-image {
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

body.collapsed-mode .sidebar {
  width: var(--sidebar-collapsed-width);
  
  /* ✅ 修正：強制頂部留 60px (Header 高度)，其他方向歸零 */
  padding-top: var(--header-height) !important;
  padding-bottom: 20px;
  padding-left: 0;
  padding-right: 0;
  
  align-items: center;
  overflow: visible !important;
}

body.collapsed-mode .fixed-header-left { left: 0; }
body.collapsed-mode .chat-page-container { margin-left: 0; max-width: 100%; }

/* Loading Animation */
.btn-loading { position: relative; color: transparent !important; pointer-events: none; opacity: 0.9; }
.btn-loading::after {
    content: ''; position: absolute; left: 50%; top: 50%; width: 20px; height: 20px;
    margin-left: -10px; margin-top: -10px;
    border: 2px solid var(--text-primary); border-top-color: transparent;
    border-radius: 50%; animation: btn-spin 0.8s infinite linear;
}
@keyframes btn-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* New Chat Button */
.new-chat-btn {
  width: 100%; padding: 12px 15px;
  background-color: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 24px;
  cursor: pointer; display: flex; align-items: center; gap: 12px;
  font-size: 14px; font-weight: 600; margin-bottom: 20px;
  box-shadow: 0 2px 5px var(--shadow-color); transition: all 0.2s ease;
}
.new-chat-btn:hover {
  background-color: var(--bg-card); border-color: var(--accent);
  box-shadow: 0 4px 8px var(--shadow-color); transform: translateY(-1px);
}

body.collapsed-mode .new-chat-btn {
    width: 44px !important;
    height: 44px !important;
    padding: 0 !important;
    margin: 10px auto 20px auto !important; /* 確保水平居中 */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
}
body.collapsed-mode .new-chat-btn span:last-child { display: none; }

/* History */
.chat-history { flex: 1; overflow-y: visible; margin-top: 0; }
.chat-history-title {
  font-size: 0.75rem; color: var(--text-muted);
  font-weight: 600; padding: 0 10px 5px;
}

.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin-bottom: 4px;
  border-radius: 20px; cursor: pointer;
  font-size: 0.9rem; color: var(--text-primary); position: relative;
}
.history-item:hover { background-color: var(--bg-hover); }
.history-item.active { 
    background-color: var(--bg-active); color: var(--primary-light); font-weight: 700; 
}

.delete-session-btn {
  position: absolute; right: 8px; background: none; border: none;
  color: var(--text-muted); display: none; padding: 4px; cursor: pointer;
}
.history-item:hover .delete-session-btn { display: block; }
.delete-session-btn:hover { color: #d32f2f; }

/* Collapsed Mode Item Fixes */
body.collapsed-mode .history-item {
  justify-content: center; padding: 10px 0;
  width: 44px; margin: 0 auto 4px auto;
}
body.collapsed-mode .history-item span,
body.collapsed-mode .history-item div { display: none; }
body.collapsed-mode .history-item svg {
  display: block !important; margin: 0; width: 20px; height: 20px;
}

.history-item svg, .menu-item svg, .new-chat-btn svg, .menu-link-item svg {
  flex-shrink: 0 !important; min-width: 20px; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
}

/* =========================================
   4. Sidebar Footer
   ========================================= */
.sidebar-footer {
  margin-top: auto; width: 100%; padding-top: 8px;
}

/* User Profile Card */
.user-profile-menu {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; margin: 10px 12px 12px 12px;
  background: var(--bg-card); border: 1px solid var(--border-sub);
  box-shadow: 0 2px 8px var(--shadow-color);
  border-radius: 12px; transition: all 0.2s ease;
}
.user-profile-menu:hover {
  box-shadow: 0 4px 12px var(--shadow-color); transform: translateY(-1px);
}

.user-info { display: flex; align-items: center; gap: 12px; flex: 1; overflow: hidden; }

.user-avatar, .user-avatar-img {
  width: 36px; height: 36px; min-width: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: var(--text-on-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; object-fit: cover;
  border: 2px solid var(--bg-card); box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin: 0;
}

.user-details {
  display: flex; flex-direction: column; justify-content: center;
  line-height: 1.2; overflow: hidden;
}
.user-name {
  font-size: 14px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px;
}
.user-tier {
  font-size: 11px; margin-top: 2px; font-weight: 500; display: inline-block;
}
.user-tier.free { color: var(--text-muted); }
.user-tier.pro {
  color: var(--primary-light); background: var(--bg-hover);
  padding: 1px 6px; border-radius: 4px; font-weight: 700; width: fit-content;
}

.logout-btn-small {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.logout-btn-small:hover { color: #ef4444; background: rgba(239, 68, 68, 0.1); }

body.collapsed-mode .user-profile-menu {
  width: 44px; height: 44px; padding: 0; margin: 10px auto;
  background: transparent; border: none; box-shadow: none;
  display: flex; align-items: center; justify-content: center;
}
body.collapsed-mode .user-info { display: contents; }
body.collapsed-mode .user-details,
body.collapsed-mode .logout-btn-small { display: none !important; }
body.collapsed-mode .user-avatar,
body.collapsed-mode .user-avatar-img { margin: 0 auto !important; }
body.collapsed-mode .guest-history-tip {display: none !important;}

/* Vertical Menu */
#signInLink {
  margin: 0 12px 5px 12px; padding: 10px 12px;
  width: auto; justify-content: flex-start;
}

.sidebar-vertical-menu {
  display: flex; flex-direction: column; padding: 0 12px; margin-bottom: 10px; gap: 4px;
}

.menu-link-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px 12px;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text-primary); font-size: 14px; font-weight: 500;
  text-decoration: none; cursor: pointer; transition: all 0.2s ease;
  text-align: left; opacity: 0.85;
}
.menu-link-item:hover { background-color: var(--bg-hover); opacity: 1; transform: translateX(2px); }

.menu-link-item.logout {
  margin-top: 5px; border-top: 1px solid var(--border-sub);
  padding-top: 14px; border-radius: 0 0 8px 8px;
}
.menu-link-item.logout:hover { background-color: rgba(254, 226, 226, 0.5); color: #ef4444; }

body.collapsed-mode .sidebar-vertical-menu { width: 100%; padding: 0; align-items: center; }
body.collapsed-mode .menu-link-item {
  justify-content: center; padding: 10px 0; width: 44px; height: 44px;
  margin: 0 auto; transform: none;
}

/* Membership Stats & Progress Bars */
.membership-stats {
    display: flex; flex-direction: column; gap: 6px;
    padding: 0 12px; margin-bottom: 10px;
    font-size: 12px; color: var(--text-secondary);
}
.stat-row { display: flex; justify-content: space-between; align-items: center; }
.stat-label { opacity: 0.8; }
.stat-value { font-weight: 600; font-family: 'Inter', monospace; color: var(--text-primary); }
.stat-value.highlight { color: var(--accent); }

body.collapsed-mode .membership-stats { display: none !important; }
body.collapsed-mode .menu-link-item span { display: none; }
body.collapsed-mode .menu-link-item svg { margin: 0; min-width: 20px; }

/* Progress Bar Styles */
.progress-container {
  width: 100%; height: 8px; background: var(--progress-track);
  border-radius: 99px; overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1); border: 1px solid rgba(0, 0, 0, 0.05);
  margin-top: 6px; position: relative;
}
.progress-bar {
  height: 100%; border-radius: 99px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1); position: relative; overflow: hidden;
}
.progress-bar.normal {
  background: linear-gradient(90deg, #064e3b 0%, #059669 50%, #10b981 100%);
  background-size: 200% 100%; animation: shimmerFlow 3s infinite linear;
}
.progress-bar.low {
  background: linear-gradient(90deg, #7f1d1d 0%, #dc2626 100%);
  background-size: 200% 100%; animation: shimmerFlow 2s infinite linear;
}
.progress-bar::before {
  content: ''; position: absolute; top: 0; left: -100%; width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.3) 50%, transparent 100%);
  transform: skewX(-20deg); animation: sweep 2.5s infinite ease-in-out; pointer-events: none;
}
@keyframes shimmerFlow { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@keyframes sweep { 0% { left: -100%; } 50% { left: 200%; } 100% { left: 200%; } }



/* =========================================
   6. Global Animations (Fade In Up)
   ========================================= */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.main-content, .legal-container, .terms-container, .privacy-container, .about-container {
    animation: fadeInUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* =========================================
   7. ★ 狀態切換邏輯 (Collapsed Mode Logic - Fix)
   ========================================= */

/* A. 縮回時 (collapsed-mode) */
/* 強制隱藏：對話列表 & 標題 */
body.collapsed-mode #historyListContainer,
body.collapsed-mode .history-list-container,
body.collapsed-mode #recentText,
body.collapsed-mode .chat-history-title {
    display: none !important; 
    overflow: visible !important;
}

/* 強制顯示：總結圖標 */
body.collapsed-mode #collapsedHistoryIcon,
body.collapsed-mode .collapsed-history-summary {
    display: flex !important;
    margin: 10px auto !important; /* 置中 */
    justify-content: center;
}

/* B. 展開時 */
/* 強制隱藏：總結圖標 */
body:not(.collapsed-mode) #collapsedHistoryIcon,
body:not(.collapsed-mode) .collapsed-history-summary {
    display: none !important;
}

/* 強制顯示：對話列表 & 標題 */
body:not(.collapsed-mode) #historyListContainer,
body:not(.collapsed-mode) #recentText {
    display: block !important;
}

/* =========================================
   1. 通知欄修正：實現真正的螢幕置中
   ========================================= */
.announcement-bar {
    position: absolute;
    top: 0;
    
    /* ★ 改動：讓它佔滿全寬，這樣 justify-content: center 才會在「螢幕正中間」 */
    left: 0; 
    width: 100%;
    
    height: var(--notify-height);
    
    /* 配色 */
    background: rgba(26, 61, 46, 0.98); 
    color: #ffffff;
    border-bottom: 1px solid var(--lex-gold, #c5a059); 
    
    display: flex;
    justify-content: center;
    align-items: center;
    
    /* ★ 關鍵：Sidebar Header 是 2000，這裡是 1001 */
    /* 這樣通知欄左邊會被 Sidebar Logo 蓋住，但文字會剛好在螢幕正中間 */
    z-index: 1001; 
    
    transition: top 0.3s ease;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* --- 文字淡入淡出動畫 --- */
#announcement-text, #announcement-link {
    transition: opacity 0.2s ease-in-out;
    opacity: 1;
}

.announcement-bar.hidden { display: none; }

.bar-link:hover {
    text-decoration: underline;
    filter: brightness(1.2); /* Hover 時變亮 */
}

.bar-link {
    color: var(--lex-gold, #c5a059); /* 金色連結 */
    margin-left: 10px;
    text-decoration: none;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* 關閉按鈕顏色自動適配 */
.close-bar-btn {
    position: absolute;
    right: 15px;
    background: none;
    border: none;
    color: var(--notify-text); /* 跟隨文字顏色 */
    opacity: 0.6;
    font-size: 22px;
    cursor: pointer;
}

.close-bar-btn:hover { opacity: 1; }

/* 鈴鐺按鈕樣 : 懸浮或放在 Header */
.notice-bell-btn .bell-dot {
    position: absolute;
    /* 位置微調，讓它更明顯 */
    top: -10px;    
    right: -10px;  
    
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 10px;
    
    background-color: #ff4d4f;
    color: white;
    font-size: 10px;
    font-weight: bold;
    line-height: 16px;
    text-align: center;
    border: 1.5px solid #fff; /* 加白邊，對比更強 */
    
    transition: transform 0.2s;
    z-index: 5000; /* 確保在最上層 */
    
    /* ★ 確保它是 Flex 佈局以垂直置中文字 */
    display: flex; 
    align-items: center;
    justify-content: center;
}

.notice-bell-btn:hover { transform: scale(1.1); }

/* --- 1. 右上角總容器 (負責固定在螢幕右上角) --- */
.top-actions-container {
    position: absolute;
    top: 25px;  /* 原始位置 */
    right: 30px;
    z-index: 4000; /* ★ 提高層級，確保它比 Notification Bar 還要高 */
    transition: top 0.3s ease;
    
    /* 確保容器可見 */
    display: flex;
    align-items: center;
    gap: 15px;
}

.top-actions-container,
.chat-header-right {
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), top 0.3s ease;
}

/* 當 Body 有 'has-notification' class 時，右上角按鈕下移 */
body.has-notification .top-actions-container {
    /* 讓它移到通知欄的下方 */
    top: calc(25px + var(--notify-height)); 
}

/* 情況 B: Chat 頁面 (Header 內的 Flex 元素) */
body.has-notification .chat-header-right {
    /* 這裡使用 transform 來移動，因為它是 Flex 佈局 */
    transform: translateY(var(--notify-height));
}

/* 鈴鐺按鈕 */
.notice-bell-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--lex-gold, #c5a059);
    cursor: pointer;
    background: transparent;
    border: none;
    z-index: 4001;
    
    /* ★ 關鍵修正：防止紅點被切掉 ★ */
    overflow: visible !important; 
}

.notice-bell-btn:hover {
    transform: scale(1.1);
}


/* 隱藏狀態 */
.bell-dot.hidden {
    display: none !important;
}


/* --- 4. 語言切換器 (強制清除舊定位) --- */
.index-lang-switcher, 
.language-switcher {
    position: relative; /* 確保它在容器內 */
    z-index: 4001;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

#announcement-text {
    transition: opacity 0.2s ease-in-out;
    opacity: 1;
}



/* =========================================
   8. 🛑 Sidebar 佈局終極修正 (The Spacer Method)
   ========================================= */

/* 1. 外框：清空所有內距，交給 Spacer 處理 */
.sidebar {
    display: flex !important; 
    flex-direction: column !important;
    height: 100vh !important; 
    height: 100dvh !important; 
    
    position: fixed !important; 
    top: 0 !important; 
    bottom: 0 !important; 
    left: 0 !important;
    
    overflow: hidden !important;
    
    /* ★ 關鍵：全部歸零，不要用 padding 推 */
    padding-top: 0 !important; 
    padding-left: 15px; 
    padding-right: 15px; 
    padding-bottom: 0;
    box-sizing: border-box !important;
}

/* 2. ★★★ 實體磚頭樣式 ★★★ */
.sidebar-spacer {
    width: 100%;
    
    /* 設定高度：Header (60px) + 緩衝 (20px) = 80px */
    height: 80px !important;
    min-height: 80px !important;
    
    /* 禁止縮小，確保它永遠佔據空間 */
    flex-shrink: 0 !important;
    background: transparent; /* 透明 */
    display: block !important;
}

/* 3. 按鈕與 Header：移除所有 margin */
.new-chat-btn, .sidebar-header { 
    flex-shrink: 0 !important; 
    margin-top: 0 !important; /* 確保緊貼著磚頭 */
}

/* 4. 歷史紀錄列表：自動填滿剩餘空間 */
.history-list-container, .chat-history {
    flex-grow: 1 !important;
    overflow-y: auto !important; 
    min-height: 0 !important; 
    height: auto !important;
    scrollbar-width: none; 
    padding-bottom: 20px;
}
.history-list-container::-webkit-scrollbar { display: none; }

/* 5. 底部 Footer */
.sidebar-footer {
    flex-shrink: 0 !important; 
    margin-top: auto !important;
    background: var(--bg-secondary) !important; 
    z-index: 20; 
    width: 100%;
    padding-bottom: calc(env(safe-area-inset-bottom) + 10px) !important; 
    padding-top: 10px;
}


/* =========================================
   9. 🔴 紅點數字 (Badge) 與圖標樣式
   ========================================= */
.collapsed-history-summary {
    position: relative !important; overflow: visible !important; 
    z-index: 100 !important; 
    /* 基礎樣式 */
    width: 40px; height: 40px; border-radius: 8px; color: var(--text-muted);
    transition: background 0.2s; cursor: pointer; align-items: center;
}
.collapsed-history-summary:hover {
    background-color: var(--bg-hover); color: var(--primary);
}

.history-count-badge {
    position: absolute !important; top: -8px !important; right: 0px !important;
    background-color: #ef4444 !important; color: #ffffff !important;
    border: 1px solid var(--bg-secondary) !important;
    min-width: 18px !important; height: 18px !important; border-radius: 99px !important;
    font-size: 10px !important; font-weight: 800 !important;
    display: flex !important; align-items: center; justify-content: center; padding: 0 4px !important;
    z-index: 101 !important; box-shadow: 0 2px 5px rgba(0,0,0,0.2) !important;
}

/* ==========================================================================
   📱 Mobile Final: Luxury Bell (Top-Right) + Sidebar Fix
   ========================================================================== */
@media (max-width: 768px) {

    /* --- 1. 基礎版面重置 --- */
    .announcement-bar { display: none !important; }
    
    body.has-notification .fixed-header-left,
    .fixed-header-left {
        top: 0 !important; width: 100% !important; padding-right: 15px !important;
    }
    
    body.has-notification .chat-main, 
    body.has-notification .main-content,
    .chat-main, .main-content {
        padding-top: 80px !important; 
    }

    /* --- 2. 🌟 鐘仔樣式 (右上角 + 金色呼吸動畫) --- */
    @keyframes pulse-gold {
        0% { box-shadow: 0 4px 15px rgba(0,0,0,0.3); }
        50% { box-shadow: 0 4px 25px rgba(197, 160, 89, 0.5); }
        100% { box-shadow: 0 4px 15px rgba(0,0,0,0.3); }
    }

    #fixed-mobile-bell {
        position: fixed !important;
        z-index: 999999 !important;
        
        /* 固定在右上角 */
        top: 100px;
        right: 20px;
        bottom: auto; 
        
        width: 50px !important; height: 50px !important; border-radius: 50% !important;
        background-color: #ffffff !important;
        border: 1px solid rgba(0,0,0,0.1) !important;
        display: flex !important; align-items: center; justify-content: center;
        cursor: pointer; padding: 0;
        
        /* 允許 JS 拖曳 (如果要鎖死位置，可改為 auto) */
        touch-action: none;

        /* 基礎陰影與轉場 */
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
        transition: transform 0.1s ease-in-out, box-shadow 0.3s ease;
        
        /* 套用呼吸動畫 */
        animation: pulse-gold 3s infinite ease-in-out;
    }

    /* 點擊時的按壓效果 */
    #fixed-mobile-bell:active {
        transform: scale(0.92);
    }
    
    #fixed-mobile-bell svg {
        width: 26px !important; height: 26px !important; 
        display: block !important;
        color: #c5a059 !important; /* 金色 */
        fill: none !important;
    }
    

    /* 紅點 */
    .bell-red-dot {
        position: absolute;
        top: 10px; right: 10px;
        width: 8px; height: 8px;
        background-color: #ff4d4f;
        border-radius: 50%;
        border: 1px solid #fff;
    }

    /* --- 3. ☁️ 氣泡樣式 (豪華彈出動畫) --- */
    #fixed-mobile-cloud {
        position: fixed;
        /* 初始位置：鐘仔下方 */
        top: 160px; right: 20px; bottom: auto;
        
        width: 280px;
        background: #fff; padding: 15px; border-radius: 12px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.25);
        z-index: 1000000 !important;
        
        /* 初始狀態：隱藏 */
        display: block;
        visibility: hidden;
        opacity: 0;
        
        /* 變形原點：右上方 */
        transform-origin: top right;
        transform: translateY(-20px) scale(0.9);

        /* 豪華轉場 */
        transition: 
            opacity 0.3s ease,
            transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
            visibility 0.3s step-end;
    }

    /* 顯示狀態 (JS切換此class) */
    #fixed-mobile-cloud.is-visible {
        visibility: visible;
        opacity: 1;
        transform: translateY(0) scale(1);
        transition-delay: 0s; 
        transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    
    /* 箭頭 (指向上方) */
    #fixed-mobile-cloud::after {
        content: ''; position: absolute; top: -8px; right: 18px;
        border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 8px solid #fff;
    }

    /* 氣泡內容文字 */
    .cloud-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; border-bottom: 1px solid #f0f0f0; padding-bottom: 5px; }
    .cloud-title { font-weight: 700; color: #1a3d2e; font-size: 14px; }
    .cloud-close { font-size: 20px; color: #999; background: none; border: none; padding: 0 5px; cursor: pointer;}
    .cloud-content { font-size: 13px; color: #4b5563; line-height: 1.5; }
    .cloud-link { display: inline-block; margin-top: 8px; color: #c5a059; font-weight: 600; font-size: 12px; text-decoration: none; }

    /* --- 4. Sidebar (側邊欄) 核心修復 --- */
    /* 這裡必須保留，否則側邊欄會壞掉 */
    .sidebar {
        position: fixed !important;
        top: 60px !important; left: 0 !important;
        height: calc(100vh - 60px) !important; width: 260px !important;
        z-index: 5000 !important;
        background-color: var(--bg-secondary) !important;
        transform: translateX(-100%) !important; /* 預設收起 */
        transition: transform 0.3s ease !important;
        display: flex !important; flex-direction: column !important;
        margin: 0 !important;
        padding: 10px 15px 20px !important;
    }

    .sidebar.active {
        transform: translateX(0) !important;
        box-shadow: 10px 0 30px rgba(0,0,0,0.2) !important;
    }

    .menu-overlay {
        display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 4999;
    }
    .menu-overlay.active { display: block !important; }

/* --- 5. 其他修正 --- */
    
    /* ★ 核心修正：同時隱藏「首頁」和「Chat頁」的舊鐘仔容器，讓 JS 生成的懸浮鐘仔接手 */
    .top-actions-container .notice-bell-btn,
    .chat-header-right .notice-bell-btn { 
        display: none !important; 
    }

    /* 調整容器位置，只保留語言按鈕 */
    .top-actions-container,
    .chat-header-right { 
        display: flex !important; 
        right: 10px !important; 
        top: 15px !important; 
        gap: 0 !important; 
    }

    .logo-area { max-width: 110px !important; }
    .logo-image { height: 60px !important; width: auto !important; }
    
    body.collapsed-mode .user-profile-menu, 
    body.collapsed-mode .user-info, 
    body.collapsed-mode .sidebar .menu-link-item span {
          display: flex !important; opacity: 1 !important; visibility: visible !important;
    }
}

@media (min-width: 769px) {
    #fixed-mobile-bell, 
    #fixed-mobile-cloud {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .language-switcher {
        position: relative !important;
        
        /* 1. 從螢幕最頂部開始 */
        top: 10px !important; 
        

        
        /* 3. 利用 Flex 自動垂直置中 */
        display: flex !important;
        align-items: center !important; 
        
        right: 10px !important;
        z-index: 4005 !important;
        
        /* 確保不被遮擋 */
        visibility: visible !important;
        opacity: 1 !important;
        
    }
    
    /* 確保按鈕顏色正確 */
    .language-switcher .lang-btn {
        color: var(--primary) !important;
        border-color: transparent !important;
    }
    .language-switcher .lang-btn.active {
        background-color: var(--primary) !important;
        color: #fff !important;
    }
}