/* --- 變數覆蓋 (Bootstrap Override) --- */
:root {
    --bs-body-font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    --bs-body-bg: transparent; 
    --primary-color: #333;
    --accent-blue: #5c6bc0; 
    --accent-light-blue: #e8eaf6; 
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-shadow: 0 8px 20px rgba(0,0,0,0.05);
    --border-radius: 16px;
}

/* --- 全域背景 --- */
body {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    padding-top: 20px;
    padding-bottom: 60px;
    color: var(--primary-color);
}

/* 背景裝飾 */
.bg-decoration {
    position: fixed;
    top: -50%; left: -50%; width: 200%; height: 200%;
    background: radial-gradient(circle at center, rgba(255,255,255,0.5) 0%, rgba(255,255,255,0) 70%);
    z-index: -1;
}

.main-container {
    max-width: 1200px;
}

/* --- App Header & 標題 --- */
.app-header {
    margin-bottom: 30px;
}
.app-header h1 {
    font-weight: 700;
    font-size: 2.2rem;
    color: var(--primary-color);
    margin-top: 10px;
    border-bottom: none;
    padding-bottom: 0;
}
/* 附屬工具 (轉蛋資料庫) 的入口 */
.companion-link {
    display: inline-block;
    margin-bottom: 10px;
    padding: 4px 14px;
    border-radius: 20px;
    background: #fff3e0;
    color: #c25700;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06);
}
.companion-link:hover { background: #ffe0b2; color: #a84a00; }
.icon-badge {
    font-size: 2rem;
    background: var(--accent-blue);
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.card-header h2 {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--accent-blue);
    border-bottom: 2px solid var(--accent-light-blue);
    padding-bottom: 8px;
    margin-bottom: 0;
    margin-top: 0;
}

/* --- 雲端狀態指示器樣式 (參考果實分配) --- */
.cloud-status {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #666;
    margin-bottom: 10px;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ccc;
    display: inline-block;
}
.status-online { background-color: #28a745; box-shadow: 0 0 5px #28a745; }
.status-saving { background-color: #ffc107; box-shadow: 0 0 5px #ffc107; }
.status-offline { background-color: #6c757d; }

/* --- Auth Styles (Login/Logout) --- */
#auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 40px;
}

#user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 5px 15px;
    border-radius: 25px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.auth-btn.login {
    border: none;
    background-color: white;
    color: #333;
    font-weight: 600;
    padding: 8px 20px;
    border-radius: 25px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.auth-btn.login:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

/* --- Admin Mode Utilities --- */
.admin-only {
    display: none !important; /* 預設隱藏 */
}
body.is-admin .admin-only {
    display: inline-block !important; /* 開啟管理員模式時顯示 */
}

/* --- 區塊卡片樣式 --- */
.section-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    padding: 20px;
    border: 1px solid rgba(0,0,0,0.05);
}

/* --- 統計儀表板 --- */
#stats-dashboard { 
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px; 
}
.stat-card {
    min-width: 280px;
    border: 1px solid var(--accent-light-blue);
    border-radius: 12px;
    padding: 20px;
    background-color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: transform 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
}
.stat-card h5 {
    color: #6c757d;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.8rem;
    margin-bottom: 5px;
}
.stat-card h3 {
    color: var(--accent-blue);
    font-size: 2rem;
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 10px;
}
.stat-card p {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

/* 篩選器卡片中的標籤樣式 */
.stat-filter-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #6c757d;
    margin-bottom: 0.25rem !important;
}
.stat-card .form-select, .stat-card .form-control {
    font-size: 0.95rem;
}

/* 讓活動卡片可滾動 */
#event-stats-content {
    max-height: 250px; 
    overflow-y: auto; 
    padding-right: 10px; 
}

/* 各活動：抽到角色數與每隻平均抽數 */
/* 各活動：左邊日期一欄 (不換行)，右邊活動名稱與抽數 */
.event-line {
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.event-date {
    flex: 0 0 auto;
    min-width: 54px;
    white-space: nowrap;
    font-size: 0.85rem;
    color: #6c757d;
    font-variant-numeric: tabular-nums;
}
.event-body {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}
.event-ratio {
    display: block;
    font-size: 0.8rem;
    color: #6c757d;
}
.ratio-summary {
    font-size: 0.9rem !important;
    color: #495057;
}

/* 每月投入趨勢 */
.trend-list {
    max-height: 250px;
    overflow-y: auto;
    padding-right: 10px;
}
.trend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.9rem;
}
.trend-label {
    flex: 0 0 auto;
    min-width: 54px;
    white-space: nowrap;
    color: #6c757d;
    font-variant-numeric: tabular-nums;
}
.trend-track {
    flex: 1;
    height: 10px;
    background-color: var(--accent-light-blue);
    border-radius: 5px;
    overflow: hidden;
}
.trend-bar {
    display: block;
    height: 100%;
    background-color: var(--accent-blue);
    border-radius: 5px;
}
.trend-value {
    flex: 0 0 52px;
    text-align: right;
    font-weight: 600;
}

/* 活動類型比例 */
.share-bar {
    display: flex;
    height: 14px;
    border-radius: 7px;
    overflow: hidden;
    background-color: var(--accent-light-blue);
    margin: 8px 0 12px;
}
.share-bar span {
    display: block;
    height: 100%;
}
.share-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}

/* --- 紀錄編輯表單 --- */
.form-label {
    font-weight: 600;
    color: var(--primary-color);
}
.form-select, .form-control {
    border-radius: 8px;
}

/* 批次編輯時，禁用欄位的樣式 */
.field-disabled {
    background-color: #e9ecef !important;
    opacity: 0.8 !important;
    cursor: not-allowed;
}

/* 編輯模式切換 */
#gacha-fieldset { transition: opacity 0.3s; }
#gacha-fieldset:disabled { opacity: 0.6; pointer-events: none; }
#history-table-body .btn-warning, #history-table-body .btn-danger { display: none; }
body.edit-mode-active #gacha-fieldset { opacity: 1; pointer-events: auto; }
body.edit-mode-active #history-table-body .btn-warning, 
body.edit-mode-active #history-table-body .btn-danger { display: inline-block; }

/* 輔助按鈕 (如編輯活動) */
.btn-subtle {
    border-color: #ced4da; 
    color: var(--accent-blue);
    background-color: #f8f9fa;
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}
.btn-subtle:hover {
    background-color: #e9ecef;
}

/* --- 歷史紀錄表格 --- */
.table-responsive {
    max-height: 60vh; 
    overflow-y: auto; 
    border: 1px solid #dee2e6;
    border-radius: var(--border-radius);
}

/* 固定表頭 */
.table-responsive thead th {
    position: sticky;
    top: 0;
    background-color: #d1d9e7; 
    z-index: 2; 
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); 
}

/* 歷史紀錄表格的標籤顏色 (左側邊框) */
tr[data-tag="honke"] { border-left: 5px solid #dc3545; } 
tr[data-tag="collab"] { border-left: 5px solid #6610f2; } 
tr[data-tag="free"] { border-left: 5px solid #198754; } 
tr[data-tag="orb"] { border-left: 5px solid #ffc107; } 

/* 輔助/操作按鈕 */
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.875rem; }

/* 資料管理按鈕組 */
.custom-btn {
    border-radius: 8px;
    font-weight: 500;
}

/* --- 懸浮工具箱菜單 --- */
.toolbox-menu-wrapper {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 9999;
    font-family: var(--bs-body-font-family);
    display: flex;
    flex-direction: column; 
    align-items: flex-end; 
    cursor: default; 
}

/* 主按鈕 */
.toolbox-main-btn {
    background: #2c3e50; 
    color: white;
    padding: 12px 24px;
    border-radius: 50px; 
    text-decoration: none;
    font-weight: 700;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    border: 2px solid rgba(255,255,255,0.5);
    
    cursor: pointer;
    margin: 0;
    font-family: inherit;
    font-size: 1rem;
    line-height: inherit;
    appearance: none;
}
.toolbox-main-btn:hover {
    background: #1f2a36;
}

/* 菜單列表容器 */
.toolbox-items-list {
    display: flex;
    flex-direction: column;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, margin-bottom 0.4s ease-in-out;
    background: white; 
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    min-width: 100%; 
    margin-bottom: 0;
}

.toolbox-menu-wrapper:hover .toolbox-items-list {
    max-height: 300px; 
    margin-bottom: 8px; 
}

/* 菜單單一項目 */
.toolbox-item {
    padding: 10px 15px;
    text-decoration: none;
    color: var(--primary-color);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    transition: background-color 0.2s;
    border-radius: 0;
    border-bottom: 1px solid rgba(0,0,0,0.05); 
    width: 100%;
}
.toolbox-item:hover {
    background-color: var(--accent-light-blue);
    color: var(--accent-blue);
}

.toolbox-item:first-child {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}
.toolbox-item:last-child {
    border-bottom: none;
}

.toolbox-item.active {
    background-color: var(--accent-blue); 
    color: white;
    font-weight: 700;
}
.toolbox-item.active:hover {
    background-color: #4b5cae;
}

/* --- 訊息提示框 (Toast) --- */
#toast-message {
    position: fixed;
    top: 20px;       
    right: 20px;     
    z-index: 10000;
    padding: 12px 20px;
    color: white;
    border-radius: 12px; 
    opacity: 0; 
    visibility: hidden;
    transition: opacity 0.4s ease-in-out, transform 0.4s ease-in-out, visibility 0.4s;
    font-family: var(--bs-body-font-family);
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
    white-space: nowrap;
    max-width: 90%; 
    transform: translateX(110%);
}

#toast-message.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(0); 
}

/* --- GitHub Project Link (左下角) --- */
.github-project-link {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 9999;
    background-color: #333; /* GitHub 黑 */
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255,255,255,0.2);
}

.github-project-link:hover {
    background-color: #000;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.3);
    color: white;
}

/* --- Modal 修正 (確保背景不透明) --- */
.modal-content {
    background-color: #ffffff !important; /* 強制白色背景 */
    color: #333 !important; /* 強制深色文字 */
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    border: none;
}
/* --- 卡池角色按鈕 (選好活動後顯示在「獲得角色」下面) --- */
.char-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--accent-light-blue);
    border-radius: 12px;
    padding: 10px 12px;
}
.char-picker-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
.char-picker-title {
    flex: 0 0 100%;
    font-size: 0.8rem;
    font-weight: 700;
    color: #555;
}
.char-picker-limited .char-picker-title { color: #ad1457; }
.char-picker-collab .char-picker-title { color: #6610f2; }
.char-chip {
    border: 1px solid #c5cae9;
    background: #fff;
    color: var(--primary-color);
    border-radius: 999px;
    padding: 3px 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.char-chip:hover { border-color: var(--accent-blue); }
/* 一個角色一組：主按鈕 (加 1 隻) + 已選時的「−」(減 1 隻) */
.char-chip-wrap { display: inline-flex; }
.char-chip-wrap.is-picked .char-chip {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}
.char-chip-wrap.is-picked .char-chip:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.char-chip-wrap.is-picked .char-chip:hover { filter: brightness(1.1); }
.char-chip-minus {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left-color: rgba(255, 255, 255, 0.6) !important;
    padding: 3px 12px;
    font-weight: 700;
}
.char-chip-count {
    margin-left: 6px;
    font-weight: 700;
    font-size: 0.8rem;
}
.char-chip:disabled { opacity: 0.6; cursor: not-allowed; }
