/* === 主題色彩變數設定 === */
:root {
    --bg-color: #ffffff;
    --text-color: #1f1f1f;
    --header-bg: rgba(255, 255, 255, 0.85);
    --msg-user-bg: #f0f4f9;
    --msg-user-text: #1f1f1f;
    --input-bg: #f0f4f9;
    --border-color: #e0e0e0;
    --modal-bg: #ffffff;
    --primary-color: #0b93f6;
}

/* 深色模式變數 */
[data-theme="dark"] {
    --bg-color: #131314;
    --text-color: #e3e3e3;
    --header-bg: rgba(19, 19, 20, 0.85);
    --msg-user-bg: #333537;
    --msg-user-text: #e3e3e3;
    --input-bg: #1e1f20;
    --border-color: #444746;
    --modal-bg: #1e1f20;
    --primary-color: #8ab4f8;
}

/* 系統預設媒體查詢 */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-color: #131314; --text-color: #e3e3e3; --header-bg: rgba(19, 19, 20, 0.85);
        --msg-user-bg: #333537; --msg-user-text: #e3e3e3; --input-bg: #1e1f20;
        --border-color: #444746; --modal-bg: #1e1f20; --primary-color: #8ab4f8;
    }
}

/* === 全局基礎 === */
* { box-sizing: border-box; margin: 0; padding: 0; }
body, html {
    position: fixed; height: 100vh; width: 100vw;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color); color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    overflow: hidden; overscroll-behavior-y: none;
    user-select: none; -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.msg-content { user-select: text; }
::-webkit-scrollbar { display: none; }
* { -ms-overflow-style: none; scrollbar-width: none; }

/* === 頂部毛玻璃導航 === */
#app-header {
    height: 60px; background: var(--header-bg);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 15px; position: fixed; top: 0; left: 0; width: 100%;
    z-index: 100; border-bottom: 1px solid var(--border-color);
    transition: transform 0.3s ease-in-out;
}
#app-header.hide-up { transform: translateY(-100%); }
.header-left { display: flex; align-items: center; gap: 10px; }
.menu-btn { background: transparent; border: none; font-size: 24px; color: var(--text-color); cursor: pointer; padding: 5px; }
.title-area { display: flex; flex-direction: column; line-height: 1.2; }
#header-title { font-size: 18px; font-weight: bold; letter-spacing: 1px; }

/* === 新版 頂部下拉選單 (Gemini App 懸浮風格) === */
.custom-dropdown-container { position: relative; display: inline-block; }
.model-dropdown-btn {
    background: transparent; border: none; outline: none;
    color: var(--text-color); font-size: 13px; font-weight: 700; opacity: 0.8;
    cursor: pointer; display: flex; align-items: center; gap: 4px; padding: 2px 0;
    transition: opacity 0.2s;
}
.model-dropdown-btn:hover { opacity: 1; }
.chevron { font-size: 10px; font-weight: bold; margin-left: 2px;}

.custom-dropdown-menu {
    position: absolute; top: 100%; left: 0; margin-top: 12px;
    background-color: var(--modal-bg); border: 1px solid var(--border-color);
    border-radius: 16px; padding: 8px 0; width: 240px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); z-index: 1000;
    display: flex; flex-direction: column;
}
.custom-dropdown-menu.hidden { display: none !important; }
.dropdown-item {
    padding: 12px 16px; display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; color: var(--text-color); transition: background 0.2s;
}
.dropdown-item:hover { background-color: var(--msg-user-bg); }
.dropdown-item .item-content { display: flex; flex-direction: column; gap: 4px; }
.dropdown-item .item-title { font-size: 15px; font-weight: 500; }
.dropdown-item .item-desc { font-size: 12px; color: gray; }
.dropdown-item .check-mark { color: var(--text-color); font-weight: bold; opacity: 0; transition: opacity 0.2s;}
.dropdown-item.active .check-mark { opacity: 1; }

/* ================================================== */

.nav-buttons button { background: transparent; border: none; font-size: 20px; margin-left: 10px; cursor: pointer; padding: 5px; border-radius: 50%; width: 40px; height: 40px; color: var(--text-color); }
.nav-buttons button.active { background: var(--msg-user-bg); }

/* === 側邊欄 Sidebar === */
.sidebar {
    position: fixed; top: 0; left: 0; width: 280px; height: 100%;
    background: var(--modal-bg); border-right: 1px solid var(--border-color);
    z-index: 200; transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column; justify-content: space-between; padding: 20px 15px;
}
.sidebar.closed { transform: translateX(-100%); }
.sidebar-top { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.new-chat-btn {
    background: var(--input-bg); color: var(--text-color); border: 1px solid var(--border-color); border-radius: 20px;
    padding: 12px; font-size: 16px; font-weight: bold; cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.sidebar-content { margin-top: 30px; flex: 1; overflow-y: auto; }
.sidebar-title { font-size: 12px; color: gray; margin-bottom: 10px; }
.sidebar-footer { 
    display: flex; justify-content: space-between; align-items: center; 
    padding-top: 15px; margin-top: 10px; border-top: 1px solid var(--border-color); 
}
.sidebar-action-btn { background: transparent; border: none; color: var(--text-color); font-size: 15px; cursor: pointer; padding: 10px; border-radius: 8px; flex: 1; text-align: center; font-weight: bold; }
.overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 150; backdrop-filter: blur(2px); transition: opacity 0.3s; }

#history-list { list-style: none; padding: 0; margin: 0; }
.history-item { padding: 12px 15px; margin-bottom: 8px; border-radius: 8px; cursor: pointer; color: var(--text-color); background: transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; border: 1px solid transparent; }
.history-item.active { background: var(--msg-user-bg); font-weight: bold; border-color: var(--primary-color); }

/* === 視圖與對話框區塊 === */
.view-container { height: 100%; width: 100%; position: absolute; top: 0; padding-top: 60px; }
#view-chat { display: flex; flex-direction: column; align-items: center; }
/* 替換這一段 */
#chat-history { 
    flex: 1; 
    width: 100%; 
    max-width: 800px; 
    overflow-y: auto; 
    padding: 20px; 
    padding-bottom: 180px; /* <--- 關鍵修改：從 100px 加大到 180px，把對話頂上來 */
    display: flex; 
    flex-direction: column; 
    gap: 24px; 
    scroll-behavior: smooth; 
}

.message { display: flex; width: 100%; max-width: 100%; line-height: 1.6; }
.ai-message { justify-content: flex-start; }
.ai-avatar { font-size: 24px; margin-right: 12px; }
.ai-message .msg-content { flex: 1; word-wrap: break-word; color: var(--text-color); }
.user-message { justify-content: flex-end; }
.user-message .msg-content { background-color: var(--msg-user-bg); color: var(--msg-user-text); padding: 12px 18px; border-radius: 20px 4px 20px 20px; max-width: 100%; word-wrap: break-word; }

/* === 複製按鈕與氣泡排版 === */
.message-wrapper { display: flex; flex-direction: column; max-width: 85%; }
.user-message .message-wrapper { align-items: flex-end; }
.ai-message .message-wrapper { align-items: flex-start; flex: 1; min-width: 0; }
.msg-footer { margin-top: 6px; padding: 0 4px; display: flex; }
.copy-btn { background: transparent; border: 1px solid var(--border-color); color: var(--text-color); font-size: 12px; font-weight: 500; padding: 5px 10px; border-radius: 14px; cursor: pointer; display: flex; align-items: center; gap: 6px; opacity: 0.6; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); }
.copy-btn:hover { opacity: 1; background-color: var(--input-bg); border-color: var(--primary-color); transform: translateY(-1px); }
.copy-btn:active { transform: scale(0.95); }
.copy-btn.success { border-color: #34c759 !important; color: #34c759 !important; background-color: rgba(52, 199, 89, 0.1) !important; opacity: 1; }

/* === 底部懸浮輸入框 === */
.input-container { position: fixed; bottom: 0; width: 100%; max-width: 800px; background: linear-gradient(to top, var(--bg-color) 70%, transparent); padding: 15px 20px 25px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.input-box { width: 100%; display: flex; align-items: center; gap: 8px; background: var(--input-bg); border-radius: 30px; padding: 8px 15px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
#chat-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text-color); font-size: 16px; resize: none; max-height: 120px; overflow-y: auto; font-family: inherit; line-height: 1.4; padding-top: 8px; }
.icon-btn { background: transparent; color: var(--text-color); border: none; font-size: 24px; cursor: pointer; display: flex; justify-content: center; align-items: center; width: 36px; height: 36px; border-radius: 50%; }
.send-btn { background: var(--text-color); color: var(--bg-color); font-size: 18px; }
#upload-preview { font-size: 12px; color: var(--primary-color); background: var(--msg-user-bg); padding: 5px 12px; border-radius: 10px; align-self: flex-start; margin-left: 20px; }

/* === 模態框 === */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1000; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(4px); }
.modal-content { background: var(--modal-bg); color: var(--text-color); padding: 24px; border-radius: 16px; width: 90%; max-width: 400px; display: flex; flex-direction: column; gap: 15px; border: 1px solid var(--border-color); }
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.close-btn { background: transparent; border: none; font-size: 24px; color: var(--text-color); cursor: pointer;}
.modal-content select, .modal-content input { width: 100%; padding: 10px; margin-top: 8px; background: var(--input-bg); color: var(--text-color); border: 1px solid var(--border-color); border-radius: 8px; outline: none; }
.btn-primary { background: var(--text-color); color: var(--bg-color); border: none; padding: 12px; border-radius: 8px; cursor: pointer; font-weight: bold;}
.btn-danger { background: #ff3b30; color: white; border: none; padding: 12px; border-radius: 8px; flex:1; cursor: pointer;}
.btn-secondary { background: var(--input-bg); color: var(--text-color); border: none; padding: 12px; border-radius: 8px; flex:1; cursor: pointer;}
.flex-row { display: flex; gap: 10px; }

/* === Live2D 介面 === */
#view-live2d { position: relative; background: url('https://i.imgur.com/3q1q.jpg') center/cover; }
#live2d-canvas { width: 100%; height: 100%; display: block; }
#live2d-subtitle { position: absolute; bottom: 80px; left: 5%; width: 90%; background: rgba(0,0,0,0.6); color: white; padding: 15px; border-radius: 10px; text-align: center; }
#live2d-mic-btn { position: absolute; bottom: 20px; right: 20px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,0.8); border: none; font-size: 24px; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }

/* === Amadeus Beta 世界線 === */
.amadeus-theme { --bg-color: #000000 !important; --text-color: #4af626 !important; --header-bg: #051a05 !important; --msg-user-bg: #4af626 !important; --msg-user-text: #000000 !important; --input-bg: #051a05 !important; --border-color: #4af626 !important; --modal-bg: #000000 !important; font-family: 'Courier New', Courier, monospace !important; }
.amadeus-theme #app-header { box-shadow: 0 0 15px #4af626; }
.amadeus-theme .input-box button { background: #4af626; color: #000; }
.amadeus-theme .ai-avatar { display: none; } 

/* === 動畫效果 === */
.slide-up { animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes slideUpFade { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.typing-indicator { display: flex; align-items: center; gap: 4px; padding: 8px 0; }
.typing-indicator span { width: 8px; height: 8px; background-color: var(--text-color); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; opacity: 0.7; }
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* === 按鈕懸停 (Hover) 與點擊動畫 === */
.menu-btn, .nav-buttons button, .icon-btn, .close-btn { transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease; }
.menu-btn:hover, .nav-buttons button:hover, .icon-btn:hover, .close-btn:hover { transform: scale(1.15); background-color: rgba(128, 128, 128, 0.15); border-radius: 50%; }
.menu-btn:active, .nav-buttons button:active, .icon-btn:active { transform: scale(0.9); }
.sidebar-action-btn, .new-chat-btn, .btn-primary, .btn-danger, .btn-secondary, .history-item { transition: transform 0.2s ease, filter 0.2s ease, background 0.2s; }
.sidebar-action-btn:hover, .new-chat-btn:hover, .btn-primary:hover, .btn-danger:hover { transform: translateY(-2px); filter: brightness(1.1); box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
.history-item:hover { background: var(--input-bg); transform: translateX(2px); }

/* === Markdown 排版 === */
.msg-content ul, .msg-content ol { margin-left: 20px; margin-top: 8px; margin-bottom: 8px; }
.msg-content li { margin-bottom: 4px; }
.msg-content p { margin-bottom: 10px; line-height: 1.6; }
.msg-content strong { color: var(--primary-color); }

/* === 手機端響應式調整 === */
@media screen and (max-width: 768px) {
    #app-header { padding: 0 10px; }
    .title-area h2 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
    .nav-buttons button { font-size: 16px; margin-left: 2px; width: 35px; height: 35px; }
    .message { max-width: 95%; }
    .user-message .msg-content { padding: 10px 14px; font-size: 15px; }
    .ai-message .msg-content { font-size: 15px; }
    .input-box { padding: 6px 10px; border-radius: 20px; }
    #chat-input { font-size: 15px; padding-top: 5px; }
}

.header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: contain;
    background-color: var(--input-bg); /* 給透明圖標加個柔和底色 */
    padding: 4px;
    margin-right: 2px;
}

/* === 完美還原 Gemini 側邊欄頂部 Header === */
.sidebar-header {
    display: flex;
    justify-content: space-between; /* 讓 Brand 在左，X按鈕 在右 */
    align-items: center;
    padding-bottom: 24px; /* 留下一點與新增對話按鈕的呼吸空間 */
}

/* 包含圖標與名字的左側群組 */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px; /* 圖標與文字的距離 */
}

/* 強制鎖死圖標大小，絕對不會再變巨大 */
.sidebar-logo {
    width: 28px; 
    height: 28px;
    object-fit: contain;
}

/* App 名字樣式 */
.sidebar-app-name {
    font-size: 18px;
    font-weight: 500; /* 使用中等粗細，更貼近 Gemini 的優雅感 */
    color: var(--text-color);
}

/* 細緻的 X 關閉按鈕 */
.sidebar-close-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 22px;
    font-weight: 300; /* 讓 X 看起來更幼細 */
    cursor: pointer;
    opacity: 0.6;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    transition: opacity 0.2s;
}

.sidebar-close-btn:hover {
    opacity: 1;
}
/* 1. 對話框本體：確保內部絕對是實色（黑/白） */
.input-box {
    position: relative;
    width: 100%;
    background: var(--input-bg) !important; /* 強制實心底色，光絕對進不去 */
    border-radius: 30px;
    
    /* 🛑 絕對不要加 z-index，這是之前讓光透進裡面的元凶 */
    
    display: flex;
    align-items: center;
    padding: 8px 15px;
    gap: 8px;
}

/* 2. 外部自由散發的光暈 */
.input-box::before {
    content: '';
    position: absolute;
    inset: -2px;         /* 控制光芒從邊緣露出來的範圍 */
    z-index: -1;         /* 關鍵：徹底躲在 var(--input-bg) 的正下方 */
    border-radius: 32px; 
    
    background: linear-gradient(90deg, #4285f4, #c58bf2, #8ab4f8, #4285f4);
    background-size: 200% 200%;
    
    /* 🛑 這裡只留 blur 讓光自由暈開，千萬不要加 transform，避免切出方形外框 */
    filter: blur(12px); 
    opacity: 0.8;
    animation: gemini-glow 4s linear infinite;
}

/* 3. 點擊輸入時光芒擴散 (可選) */
.input-box:focus-within::before {
    opacity: 1;
    filter: blur(16px);
    inset: -3px;
    transition: all 0.3s ease;
}

/* 4. 漸層流動動畫 */
@keyframes gemini-glow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* 針對 textarea 輸入框的精細調校 */
#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-color);
    font-size: 16px;
    resize: none; /* 禁止手動拉伸 */
    max-height: 120px; /* 限制最高高度 */
    overflow-y: auto;
    font-family: inherit;
    
    /* 修正對齊的關鍵設定 */
    line-height: 24px;       /* 設定明確的行高 */
    padding: 6px 0;          /* 上下留下一點對稱的呼吸空間，左右不要 padding */
    margin: 0;               /* 清除預設邊距 */
    display: block;
}

/* 確保左邊的加號按鈕和右邊的發送按鈕也是完美置中 */
.icon-btn, #chat-send {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    padding: 0;
    margin: 0;
    height: 36px; /* 固定按鈕容器高度，確保 Flex 垂直置中計算精準 */
    width: 36px;
}

