/* /styles/history-page.css - 修正滾動問題 */

#history-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh; /* 使用 vh 而不是 % */
    background: linear-gradient(160deg, #2c3e50, #34495e);
    color: white;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
    
    /* 關鍵修正：確保整個容器可以滾動 */
    overflow: hidden; /* 主容器不滾動，由子容器處理 */
}

#history-screen.visible {
    opacity: 1;
    pointer-events: auto;
}

.history-header {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0; /* 防止頭部收縮 */
    position: relative;
    z-index: 10002;
}

.history-back-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    padding: 5px 15px 5px 5px;
}

.history-title {
    font-size: 20px;
    font-weight: bold;
    margin: 0;
    margin-left: 10px;
}

.history-tabs {
    display: flex;
    gap: 10px;
    padding: 0 20px 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0; /* 防止標籤收縮 */
    background: rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10001;
}

.history-tab-btn {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #bdc3c7;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease-in-out;
}

.history-tab-btn:hover {
    background: rgba(0, 0, 0, 0.4);
    color: white;
}

.history-tab-btn.active {
    background: #2980b9;
    border-color: #3498db;
    color: white;
    font-weight: bold;
}

.view-toggle-tabs {
    padding: 15px 20px 0 20px;
    flex-shrink: 0; /* 防止切換標籤收縮 */
    background: rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10001;
}

.view-toggle-btn {
    background: none;
    border: none;
    color: #95a5a6;
    font-size: 15px;
    padding: 5px 10px;
    cursor: pointer;
    margin-right: 10px;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease-in-out;
}

.view-toggle-btn.active {
    color: white;
    font-weight: bold;
    border-bottom-color: #3498db;
}

/* 關鍵修正：創建可滾動的內容容器 */
#charts-view,
#records-view {
    flex: 1; /* 佔用剩餘空間 */
    overflow-y: auto; /* 允許垂直滾動 */
    overflow-x: hidden; /* 隱藏水平滾動 */
    
    /* 移動端滾動優化 */
    -webkit-overflow-scrolling: touch;
    
    /* 確保滾動區域有最小高度 */
    min-height: 0;
    
    /* 添加內邊距避免內容貼邊 */
    padding-bottom: 20px;
}

.history-content {
    /* 移除原本的 overflow-y: auto，因為父容器已經處理 */
    padding: 20px;
}

.chart-container {
    padding: 20px;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: none;
    max-width: 900px;
    margin: 0 auto;
    border-radius: 8px;
    margin-top: 20px;
    
    /* 確保圖表容器不會溢出 */
    box-sizing: border-box;
}

.kpi-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 20px;
    flex-wrap: wrap;
    
    /* 確保 KPI 容器不會造成滾動問題 */
    box-sizing: border-box;
}

.kpi-card {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
    padding: 15px 20px;
    text-align: center;
    min-width: 180px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    
    /* 防止卡片過大 */
    box-sizing: border-box;
    flex-shrink: 0;
}

.kpi-title {
    font-size: 14px;
    color: #bdc3c7;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 28px;
    font-weight: bold;
    color: white;
}

.history-card {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: background-color 0.2s;
    
    /* 確保卡片不會溢出 */
    box-sizing: border-box;
}

.history-card:hover {
    background: rgba(0, 0, 0, 0.3);
}

.card-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-summary-left {
    display: flex;
    flex-direction: column;
}

.card-mode {
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 5px;
}

.training-direction {
    font-size: 12px;
    color: #95a5a6;
    font-weight: normal;
    margin-left: 8px;
}

.card-date {
    font-size: 12px;
    color: #bdc3c7;
}

.card-summary-right {
    text-align: right;
}

.card-score {
    font-size: 20px;
    font-weight: bold;
    color: #4CAF50;
}

.card-score.fail {
    color: #FF9800;
}

.card-reaction-time {
    font-size: 12px;
    color: #95a5a6;
}

.card-details {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: none;
    font-size: 13px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}

.detail-item .op-name {
    color: #ecf0f1;
}

.detail-item .op-result.success {
    color: #2ecc71;
    font-weight: bold;
}

.detail-item .op-result.failure {
    color: #e74c3c;
}

.history-message {
    text-align: center;
    padding: 50px;
    font-size: 16px;
    color: #95a5a6;
}

.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    flex-shrink: 0; /* 防止分頁控制收縮 */
    background: rgba(0, 0, 0, 0.1);
    /* 移除 position: sticky，讓它自然流動 */
}

.pagination-btn {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 5px 12px;
    margin: 0 5px;
    border-radius: 5px;
    cursor: pointer;
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    font-size: 14px;
    margin: 0 10px;
}

.stage-details {
    margin-top: 10px;
    padding-left: 15px;
    border-left: 2px solid #3498db;
}

.custom-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding-bottom: 10px;
    font-size: 12px;
    flex-wrap: wrap; /* 允許圖例換行 */
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.legend-item-hidden {
    opacity: 0.5;
    text-decoration: line-through;
}

.legend-symbol {
    display: inline-block;
}

.legend-symbol-rect {
    width: 20px;
    height: 12px;
}

.legend-symbol-circle {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* 移動端特殊優化 */
@media (max-width: 768px) {
    .kpi-container {
        flex-direction: column;
        align-items: center;
    }
    
    .kpi-card {
        width: 100%;
        max-width: 300px;
    }
    
    .custom-legend {
        flex-direction: column;
        gap: 10px;
    }
    
    .chart-container {
        padding: 10px;
        margin-top: 10px;
    }
    
    .history-content {
        padding: 10px;
    }
}