/* ===== 使用主程式主題變數 ===== */
/* navbar-height 現在由全局 header.ejs 定義，不要在此重複定義 */

/* ===== 全局樣式 ===== */
* {
    box-sizing: border-box;
}

/* 保留重置但排除 body 的 padding（由全局 navbar 樣式處理） */
.app-container *,
.top-bar *,
.view-container * {
    margin: 0;
    padding: 0;
}

/* 確保導引列不受全局樣式影響 */
.navbar,
.navbar *,
#mainNavbar,
#mainNavbar * {
    box-sizing: border-box;
}

.app-container {
    max-width: 100vw;
    min-height: calc(100vh - var(--navbar-height, 56px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(180deg, var(--theme-bg-primary, #0f1419) 0%, var(--theme-bg-secondary, #1a1f2e) 100%);
    color: var(--theme-text-primary, #f0f6fc);
}

/* ===== 頂部控制欄 ===== */
/* 注意：top-bar的樣式現在在aiscientist.ejs中定義，這裡保留作為備用 */
.top-bar {
    background: var(--theme-bg-secondary, #1a1f2e);
    backdrop-filter: blur(10px);
    padding: 1rem 4rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px var(--theme-shadow, rgba(0, 0, 0, 0.3));
    border-bottom: 1px solid var(--theme-border, #30363d);
}

.top-bar h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--theme-text-primary, #f0f6fc);
    margin: 0;
}

.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* ===== 模式切換按鈕 ===== */
.mode-toggle {
    display: flex;
    gap: 0.5rem;
    background: var(--theme-bg-tertiary, #2a2f3e);
    padding: 0.25rem;
    border-radius: 0.5rem;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-text-secondary, #8b949e);
    transition: all 0.2s;
}

.mode-btn:hover {
    background: var(--theme-hover, rgba(177, 186, 196, 0.12));
}

.mode-btn.active {
    background: var(--theme-accent, #58a6ff);
    color: white;
    box-shadow: 0 2px 8px rgba(88, 166, 255, 0.3);
}

.mode-btn .icon {
    font-size: 1.25rem;
}

/* ===== 人物篩選 ===== */
.people-filter {
    position: relative;
}

.filter-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--theme-border, #30363d);
    background: var(--theme-bg-tertiary, #2a2f3e);
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-text-primary, #f0f6fc);
    transition: all 0.2s;
}

.filter-btn:hover {
    border-color: var(--theme-accent, #58a6ff);
    box-shadow: 0 2px 8px rgba(88, 166, 255, 0.2);
}

.filter-btn .count {
    background: var(--theme-accent, #58a6ff);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    min-width: 1.5rem;
    text-align: center;
}

.filter-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: var(--theme-bg-secondary, #1a1f2e);
    border: 1px solid var(--theme-border, #30363d);
    border-radius: 0.5rem;
    box-shadow: 0 10px 30px var(--theme-shadow, rgba(0, 0, 0, 0.3));
    width: 300px;
    max-height: 400px;
    overflow: hidden;
    z-index: 1000;
    transition: all 0.2s;
}

.filter-dropdown.hidden {
    display: none;
}

.search-input {
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-bottom: 1px solid var(--theme-border, #30363d);
    background: var(--theme-input-bg, #0d1117);
    color: var(--theme-text-primary, #f0f6fc);
    font-size: 0.875rem;
    outline: none;
}

.search-input:focus {
    border-bottom-color: var(--theme-accent, #58a6ff);
}

.people-list {
    max-height: 350px;
    overflow-y: auto;
    padding: 0.5rem;
}

.person-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background 0.2s;
    color: var(--theme-text-primary, #f0f6fc);
}

.person-item:hover {
    background: var(--theme-hover, rgba(177, 186, 196, 0.12));
}

.person-item input[type="checkbox"] {
    cursor: pointer;
}

.person-item label {
    cursor: pointer;
    flex: 1;
    font-size: 0.875rem;
}

/* ===== 視圖容器 ===== */
.view-container {
    flex: 1;
    display: none;
    overflow: hidden;
    height: calc(100vh - 56px); /* 減去navbar的高度 */
}

.view-container.active {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px);
}


/* ===== 故事模式視圖 ===== */
.timeline-wrapper {
    display: flex;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.vertical-timeline {
    width: 120px;
    background: var(--theme-bg-secondary, #1a1f2e);
    border-right: 1px solid var(--theme-border, #30363d);
    overflow-y: auto;
    overflow-x: hidden;
    position: fixed;
    left: 0;
    top: 56px; /* 從 navbar 下方開始，讓背景填滿上方空白 */
    height: calc(100vh - 56px);
    padding: 0;
    z-index: 0; /* 比 top-bar (z-index: 100) 低，讓 top-bar 顯示在上層 */
    flex-shrink: 0;
}


/* 時間軸連接線 - 在左側 */
.vertical-timeline::before {
    content: '';
    position: absolute;
    left: 24px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--theme-border, #30363d);
    z-index: 1;
}

.timeline-track {
    padding: 84px 0 1rem 0; /* 上方留空間 (top-bar高度約60px + 24px額外空間 = 84px)，讓數字從適當位置開始 */
    position: relative;
    z-index: 2;
}

.timeline-marker {
    padding: 0.75rem 0.5rem 0.75rem 40px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--theme-text-secondary, #8b949e);
    text-align: left;
    transition: color 0.2s ease;
    cursor: pointer;
    position: relative;
    margin: 0.5rem 0;
    z-index: 2;
}

/* 圓點標記 - 在軸線上 */
.timeline-marker::before {
    content: '';
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: var(--theme-text-muted, #6e7681);
    border-radius: 50%;
    transition: all 0.2s ease;
    z-index: 4;
}

/* 懸停效果 - 簡化版 */
.timeline-marker:hover {
    color: var(--theme-accent, #58a6ff);
}

.timeline-marker:hover::before {
    width: 10px;
    height: 10px;
    background: var(--theme-accent, #58a6ff);
    left: 24px;
    transform: translate(-50%, -50%);
}

/* 活動狀態 - 簡化版 */
.timeline-marker.active {
    color: var(--theme-accent, #58a6ff);
    font-weight: 600;
}

.timeline-marker.active::before {
    width: 12px;
    height: 12px;
    background: var(--theme-accent, #58a6ff);
    left: 24px;
    transform: translate(-50%, -50%);
}

/* 滾動條美化 */
.vertical-timeline::-webkit-scrollbar {
    width: 6px;
}

.vertical-timeline::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.vertical-timeline::-webkit-scrollbar-thumb {
    background: rgba(88, 166, 255, 0.4);
    border-radius: 3px;
    transition: background 0.3s;
}

.vertical-timeline::-webkit-scrollbar-thumb:hover {
    background: rgba(88, 166, 255, 0.6);
}

/* ===== 事件卡片容器 ===== */
.events-container {
    flex: 1;
    overflow-y: auto;
    background: var(--theme-bg-primary, #0f1419);
    padding: 2rem;
    height: 100%;
    margin-left: 120px; /* 為固定時間軸留出空間 */
}

.events-list {
    max-width: 900px;
    margin: 0 auto;
}

.event-card {
    background: var(--theme-card-bg, #1a1f2e);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 20px var(--theme-shadow, rgba(0, 0, 0, 0.3));
    border: 1px solid var(--theme-border, #30363d);
    border-left: 4px solid transparent;
    transition: all 0.3s ease;
    animation: fadeInUp 0.5s ease-out;
    position: relative;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.event-card:hover {
    box-shadow: 0 8px 30px var(--theme-shadow, rgba(0, 0, 0, 0.4));
    transform: translateY(-2px);
    border-color: var(--theme-accent, #58a6ff);
}

.event-card.type-research {
    border-left-color: var(--theme-info, #58a6ff);
}

.event-card.type-company {
    border-left-color: var(--theme-success, #3fb950);
}

.event-card.type-conference {
    border-left-color: var(--theme-warning, #d29922);
}

.event-card.type-career {
    border-left-color: #8b5cf6;
}

.event-card.type-milestone {
    border-left-color: var(--theme-danger, #f85149);
}

.event-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.event-year {
    display: inline-block;
    background: linear-gradient(135deg, var(--theme-accent, #58a6ff) 0%, #79c0ff 100%);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.event-type-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.event-type-badge.research { 
    background: rgba(88, 166, 255, 0.2); 
    color: var(--theme-info, #58a6ff); 
}
.event-type-badge.company { 
    background: rgba(63, 185, 80, 0.2); 
    color: var(--theme-success, #3fb950); 
}
.event-type-badge.conference { 
    background: rgba(210, 153, 34, 0.2); 
    color: var(--theme-warning, #d29922); 
}
.event-type-badge.career { 
    background: rgba(139, 92, 246, 0.2); 
    color: #8b5cf6; 
}
.event-type-badge.milestone { 
    background: rgba(248, 81, 73, 0.2); 
    color: var(--theme-danger, #f85149); 
}

.event-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--theme-text-primary, #f0f6fc);
    margin-bottom: 0.75rem;
}

.event-description {
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--theme-text-secondary, #8b949e);
    margin-bottom: 1rem;
}

.event-description.collapsed {
    max-height: 3.6em;
    overflow: hidden;
    position: relative;
}

.event-description.collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1.8em;
    background: linear-gradient(transparent, var(--theme-bg-primary, #0f1419));
}

.expand-btn {
    background: none;
    border: none;
    color: var(--theme-accent, #58a6ff);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.25rem 0;
    transition: color 0.2s;
}

.expand-btn:hover {
    color: var(--theme-accent-hover, #79c0ff);
}

.event-people {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.person-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.75rem;
    background: var(--theme-bg-tertiary, #2a2f3e);
    border: 1px solid var(--theme-border, #30363d);
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    color: var(--theme-text-secondary, #8b949e);
    cursor: pointer;
    transition: all 0.2s;
}

.person-tag:hover {
    background: var(--theme-accent, #58a6ff);
    color: white;
    border-color: var(--theme-accent, #58a6ff);
}

/* ===== 人才流動全局圖視圖 ===== */
.flow-controls {
    background: var(--theme-bg-secondary, #1a1f2e);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--theme-border, #30363d);
}

.time-range-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.time-range-control label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-text-primary, #f0f6fc);
}

.year-input {
    width: 80px;
    padding: 0.5rem;
    border: 1px solid var(--theme-border, #30363d);
    background: var(--theme-input-bg, #0d1117);
    color: var(--theme-text-primary, #f0f6fc);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    text-align: center;
}

.year-input:focus {
    outline: none;
    border-color: var(--theme-accent, #58a6ff);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
}

.reset-btn {
    padding: 0.5rem 1rem;
    background: var(--theme-bg-tertiary, #2a2f3e);
    border: 1px solid var(--theme-border, #30363d);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--theme-text-primary, #f0f6fc);
    cursor: pointer;
    transition: all 0.2s;
}

.reset-btn:hover {
    background: var(--theme-hover, rgba(177, 186, 196, 0.12));
}

.legend {
    display: flex;
    gap: 1.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--theme-text-secondary, #8b949e);
}

.legend-color {
    width: 20px;
    height: 12px;
    border-radius: 0.25rem;
}

.flow-visualization {
    flex: 1;
    background: var(--theme-bg-primary, #0f1419);
    overflow: auto;
    position: relative;
}

/* ===== D3.js 視覺化樣式（改進版） ===== */
.career-bar {
    transition: all 0.3s ease;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    cursor: pointer;
}

.career-bar:hover {
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    opacity: 1 !important;
}

.career-bar.highlighted {
    stroke: var(--theme-accent, #58a6ff);
    stroke-width: 2;
    filter: drop-shadow(0 4px 12px rgba(88, 166, 255, 0.4));
}

.connection-line {
    transition: all 0.3s ease;
}

.connection-line.highlighted {
    stroke-width: 3;
    opacity: 1 !important;
}

.company-label text {
    font-weight: 600;
    font-size: 14px;
    fill: var(--theme-text-primary, #f0f6fc);
}

.milestone-marker {
    cursor: pointer;
    transition: all 0.3s ease;
}

.milestone-marker:hover {
    transform: scale(1.2);
}

.milestone-label {
    font-size: 11px;
    font-weight: 500;
    pointer-events: none;
    fill: var(--theme-text-secondary, #8b949e);
}

/* ===== Tooltip ===== */
.tooltip {
    position: fixed;
    background: var(--theme-bg-secondary, #1a1f2e);
    border: 1px solid var(--theme-border, #30363d);
    color: var(--theme-text-primary, #f0f6fc);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.5;
    max-width: 350px;
    pointer-events: none;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    box-shadow: 0 4px 12px var(--theme-shadow, rgba(0, 0, 0, 0.3));
}

.tooltip.show {
    opacity: 1;
    visibility: visible;
}

.tooltip strong {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--theme-accent, #58a6ff);
}

/* ===== 滾動條樣式 ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--theme-bg-secondary, #1a1f2e);
}

::-webkit-scrollbar-thumb {
    background: var(--theme-text-muted, #6e7681);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--theme-text-secondary, #8b949e);
}

/* ===== 響應式設計 ===== */
@media (max-width: 768px) {
    .top-bar {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .top-bar h1 {
        font-size: 1.25rem;
    }
    
    .controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .vertical-timeline {
        width: 100px;
        top: 56px; /* 確保從 navbar 下方開始 */
        height: calc(100vh - 56px);
        position: fixed; /* 確保固定定位 */
        left: 0;
        z-index: 0; /* 確保 z-index 正確 */
    }
    
    .timeline-track {
        padding: 84px 0 1rem 0; /* 保持與桌面版一致的 padding */
    }
    
    .timeline-marker {
        padding: 0.5rem 0.25rem 0.5rem 32px; /* 調整左側 padding 適應較窄的寬度 */
        font-size: 0.75rem;
    }
    
    .timeline-marker::before {
        left: 20px; /* 調整軸線位置適應較窄的寬度 */
    }
    
    .timeline-marker:hover::before,
    .timeline-marker.active::before {
        left: 20px; /* 確保懸停和活動狀態的圓點也在正確位置 */
    }
    
    .vertical-timeline::before {
        left: 20px; /* 調整軸線位置適應較窄的寬度 */
    }
    
    .events-container {
        padding: 1rem;
        margin-left: 100px;
    }
    
    .event-card {
        padding: 1rem;
    }
    
    .flow-controls {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
}

/* ===== Loading 狀態 ===== */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 3rem;
    color: var(--theme-text-secondary, #8b949e);
}

.loading::after {
    content: '載入中...';
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ===== X軸樣式 ===== */
.x-axis line,
.x-axis path {
    stroke: var(--theme-border, #30363d);
}

.x-axis text {
    fill: var(--theme-text-secondary, #8b949e);
}
