/* --- Google 字體 --- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&display=swap');

/* --- [主題] CSS 變數定義 (預設為流光漸變主題) --- */
:root {
    --theme-bg-image: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    --theme-bg-color: #fff; /* A fallback color */
    --theme-bg-size: 400% 400%;
    --theme-bg-animation: gradientBG 15s ease infinite;

    --card-bg: rgba(255, 255, 255, 0.6);
    --card-border-color: rgba(255, 255, 255, 0.2);
    --card-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);

    --text-primary: #1f2937;   /* gray-800 */
    --text-secondary: #4b5563; /* gray-600 */
    --text-muted: #6b7280;     /* gray-500 */
    
    --accent-color: #4f46e5;      /* indigo-600 */
    --accent-color-light: #e0e7ff; /* indigo-100 */
    --accent-shadow: rgba(99, 102, 241, 0.3);

    --success-color: #16a34a; /* green-600 */
    --danger-color: #dc2626;  /* red-600 */
    --info-color: #2563eb;    /* blue-600 */

    --input-bg: rgba(255, 255, 255, 0.5);
    --input-border-color: rgba(255, 255, 255, 0.4);
    --input-focus-bg: #ffffff;

    --active-view-bg: #ffffff;
    --chart-legend-color: #374151;
}

/* --- [主題] 淺色模式 (Light) --- */
body[data-theme="light"] {
    --theme-bg-image: none;
    --theme-bg-color: #f3f4f6; /* gray-100 */
    --theme-bg-animation: none;
    --card-bg: rgba(255, 255, 255, 0.8);
    --card-border-color: rgba(230, 230, 230, 0.8);
}

/* --- [主題] 深色模式 (Dark) --- */
body[data-theme="dark"] {
    --theme-bg-image: none;
    --theme-bg-color: #111827; /* gray-900 */
    --theme-bg-animation: none;

    --card-bg: rgba(31, 41, 55, 0.6);
    --card-border-color: rgba(255, 255, 255, 0.1);
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);

    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;

    --success-color: #4ade80;
    --danger-color: #f87171;
    --info-color: #60a5fa;

    --input-bg: rgba(55, 65, 81, 0.5);
    --input-border-color: rgba(255, 255, 255, 0.1);
    --input-focus-bg: #374151;

    --active-view-bg: #374151;
    --chart-legend-color: #d1d5db;
}

/* --- [主題] 自訂圖片模式 (Custom Image) --- */
body[data-theme="custom"] {
    --theme-bg-image: var(--custom-bg-image); /* This is set by JS */
    --theme-bg-color: #111827; /* Dark fallback while image loads */
    --theme-bg-animation: none;
    
    background-size: cover; 
    background-repeat: no-repeat;
    
    --card-bg: rgba(255, 255, 255, 0.75); 
    --card-border-color: rgba(255, 255, 255, 0.3);
    --card-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);

    --text-primary: #1f2937;
    --text-secondary: #374151;
    --text-muted: #4b5563;
}

/* --- [主題] 自訂影片模式 (Custom Video) --- */
body[data-theme="custom-video"] {
    --theme-bg-image: none;
    --theme-bg-color: #111827;
    --theme-bg-animation: none;

    --card-bg: rgba(255, 255, 255, 0.75);
    --card-border-color: rgba(255, 255, 255, 0.3);
    --card-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);

    --text-primary: #1f2937;
    --text-secondary: #374151;
    --text-muted: #4b5563;
}

/* 背景影片層：預設隱藏，切到 custom-video 顯示 */
.bg-video {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    object-fit: cover;
    z-index: -2;           /* 影片在最底層 */
    pointer-events: none;  /* 避免擋住操作 */
    opacity: 0; visibility: hidden;
    transition: opacity .35s ease;
    background: #000;      /* 影片空白載入時的底色 */
}
body[data-theme="custom-video"] .bg-video {
    opacity: 1; visibility: visible;
}

/* 圖片/影片共同遮罩層（壓暗背景，凸顯內容） */
body[data-theme="custom"]::before,
body[data-theme="custom-video"]::before {
    content: '';
    position: fixed;
    top: 0; left: 0; height: 100%; width: 100%;
    background-color: rgba(0, 0, 0, 0.25);
    z-index: -1;
}

body {
    font-family: 'Noto Sans TC', sans-serif;
    
    background-color: var(--theme-bg-color);
    background-image: var(--theme-bg-image);
    background-size: var(--theme-bg-size, cover);
    background-position: center;
    background-attachment: fixed;
    animation: var(--theme-bg-animation);
    
    color: var(--text-primary);
    transition: background 0.5s ease-in-out;
    position: relative;
    z-index: 0;
}

body[data-theme="loading"] {
    transition: background 0.3s ease-in-out;
    background: var(--theme-bg-color);
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* --- 琉璃質感 (Glassmorphism) --- */
.card-glass {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border-color);
    box-shadow: var(--card-shadow);
}

/* --- 通用表單元件 --- */
.form-input {
    margin-top: 0.25rem; display: block; width: 100%;
    border: 1px solid var(--input-border-color);
    border-radius: 0.375rem; padding: 0.5rem;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
    background: var(--input-bg);
    color: var(--text-primary);
}
.form-input:focus {
    outline: 2px solid transparent; outline-offset: 2px;
    box-shadow: 0 0 0 3px var(--accent-shadow);
    border-color: var(--accent-color);
    background: var(--input-focus-bg);
}
.form-input::placeholder { color: var(--text-muted); }

/* --- 交易紀錄列表 --- */
.transaction-list li { border-bottom: 1px solid var(--input-border-color); }
.transaction-list li:last-child { border-bottom: none; }
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }

/* --- 通用按鈕 --- */
button { letter-spacing: 0.5px; transition: all 0.15s ease-in-out; }
button:active { transform: scale(0.97); filter: brightness(0.95); }

/* --- 數據總覽卡片 --- */
.stat-card {
    padding: 1.5rem; border-radius: 0.75rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.stat-card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 0 20px var(--accent-shadow);
}
.stat-card .text-green-600, .text-green-600, .text-green-500 { color: var(--success-color); }
.stat-card .text-red-600, .text-red-700, .text-red-500 { color: var(--danger-color); }
.stat-card .text-blue-600 { color: var(--info-color); }

/* --- 檢視模式切換按鈕 --- */
.view-btn { padding: 0.25rem 1rem; border-radius: 0.5rem; font-weight: 500; color: var(--text-secondary); }
.active-view {
    background-color: var(--active-view-bg);
    color: var(--accent-color);
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    transform: scale(1.1);
}
.active-view:active { transform: scale(1.05); }

/* --- 圖表容器 --- */
.chart-container { position: relative; height: 350px; width: 100%; }

/* --- 分類列表 --- */
.category-list { max-height: 150px; overflow-y: auto; }
.category-list::-webkit-scrollbar { width: 5px; }
.category-list::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); border-radius: 10px;}
.category-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.3); border-radius: 10px;}
.category-list::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.4); }

/* --- 編輯彈出視窗 (Modal) --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    display: flex; justify-content: center; align-items: center; z-index: 1000;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}
.modal-content {
    padding: 2rem; border-radius: 0.75rem;
    width: 90%; max-width: 500px;
    animation: fadeIn 0.3s ease-out forwards;
}

/* --- 動畫 & 特效 --- */
.list-move, .list-enter-active, .list-leave-active { transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1); }
.list-enter-from, .list-leave-to { opacity: 0; transform: scaleY(0.01) translate(30px, 0); }
.list-leave-active { position: absolute; width: 100%; }

.spinner-container { display: flex; justify-content: center; align-items: center; padding: 40px 0; }
.spinner {
    width: 56px; height: 56px; border-radius: 50%; border: 9px solid;
    border-color: var(--accent-color-light);
    border-right-color: var(--accent-color);
    animation: spinner-d3wgkg 1s infinite linear;
}
@keyframes spinner-d3wgkg { to { transform: rotate(1turn); } }

.fade-in-up { opacity: 0; animation: fadeInUp 0.6s ease-out forwards; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.delay-100 { animation-delay: 0.1s; } .delay-200 { animation-delay: 0.2s; }
.delay-300 { animation-delay: 0.3s; } .delay-400 { animation-delay: 0.4s; }
.delay-500 { animation-delay: 0.5s; }

/* --- 主題選擇器（左上角） --- */
.theme-switcher { position: fixed; top: 2rem; left: 2rem; z-index: 1001; }
.theme-fab {
    width: 56px; height: 56px; background-color: var(--accent-color);
    color: white; border-radius: 50%; display: flex;
    justify-content: center; align-items: center; font-size: 24px;
    cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transition: transform 0.2s ease-in-out;
}
.theme-fab:hover { transform: scale(1.1); }
.theme-panel {
    position: fixed;
    top: calc(2rem + 56px + 12px); /* FAB 下方一點距離 */
    left: 2rem;
    width: 220px;
    padding: 1rem;
    border-radius: 0.75rem;
    transform-origin: top left;
    animation: fadeInUp 0.3s ease;
    z-index: 1002;
    max-height: none;
    overflow: visible;
}
.theme-panel h4 { margin-top: 0; margin-bottom: 0.75rem; font-weight: bold; color: var(--text-primary); }

/* --- 兩層選單結構 --- */
.theme-options { display: flex; flex-direction: column; gap: 0.5rem; }
.settings-group { position: relative; }
.settings-main-btn {
    display: flex; align-items: center; width: 100%;
    text-align: left; padding: 0.65rem 0.75rem; border-radius: 0.375rem;
    cursor: pointer; font-weight: 600;
    background-color: rgba(128,128,128,0.15); color: var(--text-primary);
    border: 1px solid var(--input-border-color); transition: all 0.2s ease-in-out;
}
.settings-main-btn:hover { background-color: rgba(128,128,128,0.25); border-color: var(--accent-color); transform: translateX(2px); }
.settings-main-btn i:last-child { font-size: 0.75rem; opacity: 0.6; transition: transform 0.2s ease-in-out; }
.settings-group:hover .settings-main-btn i:last-child { transform: translateX(2px); }

.settings-submenu {
    position: absolute; left: 100%; top: 0; margin-left: 0.5rem;
    width: 200px; padding: 0.75rem; border-radius: 0.5rem;
    background: var(--card-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--card-border-color); box-shadow: var(--card-shadow);
    opacity: 0; visibility: hidden; transform: translateX(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
    pointer-events: none; z-index: 10;
    max-height: none; overflow: visible;
}
.settings-group:hover .settings-submenu { opacity: 1; visibility: visible; transform: translateX(0); pointer-events: auto; }

.settings-submenu button,
.settings-submenu .upload-btn {
    display: flex; align-items: center; width: 100%;
    text-align: left; padding: 0.5rem 0.65rem; margin-bottom: 0.375rem;
    border-radius: 0.375rem; cursor: pointer; font-weight: 500; font-size: 0.875rem;
    background-color: rgba(128,128,128,0.1); color: var(--text-secondary);
    border: 1px solid transparent; transition: all 0.2s ease-in-out;
}
.settings-submenu button:last-child, .settings-submenu .upload-btn:last-child { margin-bottom: 0; }
.settings-submenu button:hover, .settings-submenu .upload-btn:hover { background-color: rgba(128,128,128,0.2); color: var(--text-primary); transform: translateX(3px); }
.settings-submenu button.active { background-color: rgba(79,70,229,0.15); border-color: var(--accent-color); color: var(--accent-color); font-weight: bold; }
.settings-submenu button:active { transform: scale(0.97) translateX(3px); }

.submenu-hint { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.5rem; padding: 0.25rem 0.5rem; background-color: rgba(128,128,128,0.05); border-radius: 0.25rem; }
.submenu-hint .font-bold { color: var(--accent-color); }
.submenu-divider { border: 0; height: 1px; background-color: var(--card-border-color); margin: 0.5rem 0; }

.custom-bg-item { display: flex; align-items: center; gap: 0.375rem; margin-bottom: 0.375rem; }
.custom-bg-item button:first-child { flex-grow: 1; margin-bottom: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.delete-bg-btn {
    flex-shrink: 0; width: 24px !important; height: 24px !important; padding: 0 !important; font-size: 11px !important;
    display: flex; justify-content: center; align-items: center; border-radius: 4px;
    background-color: #ef4444 !important; color: white !important; border: none !important; line-height: 1; margin-bottom: 0 !important;
    transition: all 0.2s ease-in-out;
}
.delete-bg-btn:hover { background-color: #dc2626 !important; transform: scale(1.15) translateX(0) !important; box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4); }
.delete-bg-btn:active { transform: scale(0.95) translateX(0) !important; }

/* 永不休眠按鈕特殊樣式 */
.never-sleep-btn.active { background-color: rgba(220,38,38,0.1) !important; border-color: var(--danger-color) !important; color: var(--danger-color) !important; }

/* --- 右上角「帳戶切換器」 --- */
.account-switcher {
    position: fixed;
    top: 2rem;
    right: 2rem;  /* 改為右上角 */
    left: auto;
    z-index: 1001;
}
.account-fab {
    height: 44px; padding: 0 12px; border-radius: 9999px;
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--card-bg); border: 1px solid var(--card-border-color);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--card-shadow); color: var(--text-primary);
    transition: transform .15s ease, filter .15s ease;
}
.account-fab:hover { transform: translateY(-1px); filter: brightness(1.03); }
.account-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;     /* 面板靠右對齊 */
    left: auto;
    width: 220px;
    padding: 8px; border-radius: 12px;
    background: var(--card-bg); border: 1px solid var(--card-border-color);
    box-shadow: var(--card-shadow); z-index: 1002;
}
.account-panel button { width: 100%; text-align: left; }

/* 休眠時隱藏帳戶切換器（若未用 v-if 控制時） */
.sleep-mode-container.sleeping ~ .account-switcher { opacity: 0; pointer-events: none; }

/* --- 休眠模式樣式 --- */
.sleep-mode-container { transition: opacity 0.8s ease-in-out, transform 0.8s ease-in-out; }
.sleep-mode-container.sleeping { opacity: 0; transform: scale(0.95); pointer-events: none; }

/* 休眠時隱藏主題切換器 */
.sleep-mode-container.sleeping .theme-switcher { opacity: 0; pointer-events: none; }

/* --- 喚醒提示訊息 --- */
.wake-up-hint {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    z-index: 999; padding: 2rem 3rem; border-radius: 1rem;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 255, 255, 0.3); box-shadow: 0 8px 32px 0 rgba(0,0,0,0.1);
    text-align: center; color: white; font-size: 1.5rem; font-weight: 500;
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
    opacity: 0; animation: fadeInPulse 2s ease-in-out infinite; pointer-events: none;
    user-select: none; -webkit-user-select: none; -moz-user-select: none;
}
@keyframes fadeInPulse {
    0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* 深色/淺色主題下的喚醒提示調整 */
body[data-theme="dark"] .wake-up-hint { background: rgba(31,41,55,0.3); border-color: rgba(255,255,255,0.2); }
body[data-theme="light"] .wake-up-hint {
    background: rgba(255,255,255,0.25); border-color: rgba(0,0,0,0.1);
    color: #1f2937; text-shadow: 0 1px 3px rgba(255,255,255,0.8);
}

/* --- 休眠模式圖示動畫 --- */
.wake-up-hint i { display: block; font-size: 3rem; margin-bottom: 1rem; animation: floatIcon 3s ease-in-out infinite; }
@keyframes floatIcon { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

/* --- 響應式調整（保持完整顯示，不加內部滾軸） --- */
@media (max-width: 768px) {
    .wake-up-hint { padding: 1.5rem 2rem; font-size: 1.2rem; }
    .wake-up-hint i { font-size: 2.5rem; }

    .theme-panel { width: 200px; }
    .settings-submenu { width: 180px; }
    .settings-main-btn { font-size: 0.875rem; padding: 0.6rem 0.65rem; }
    .settings-submenu button, .settings-submenu .upload-btn { font-size: 0.8rem; padding: 0.45rem 0.6rem; }

    .account-panel { width: 200px; }
}

/* --- 子選單箭頭指示器（左上角：箭頭在左側，指向右邊） --- */
.settings-submenu::after {
    content: ''; position: absolute; left: -6px; top: 12px; width: 0; height: 0;
    border-style: solid; border-width: 6px 6px 6px 0;
    border-color: transparent var(--card-border-color) transparent transparent;
}