/* style.css */

/* 通用樣式 */
body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f0f2f5;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* 保持頂部對齊 */
    min-height: 100vh; /* 確保內容至少佔滿整個視窗高度 */
    overflow-y: auto; /* 允許垂直滾動 */
}

.container {
    display: flex;
    flex-direction: row;
    width: 95%; /* 響應式寬度 */
    max-width: 1400px; /* 最大寬度 */
    margin: 20px auto; /* 居中並提供上下邊距 */
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden; /* 隱藏溢出內容 */
    min-height: 80vh; /* 最小高度 */
}

/* 左側面板 */
.left-panel {
    flex: 0 0 300px; /* Default width */
    border-right: 1px solid #eee;
    padding: 20px;
    background-color: #fdfdfd;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Allow vertical scrolling */
    transition: flex-basis 0.3s ease, padding 0.3s ease; /* Smooth transition for width and padding */
}

.left-panel.collapsed {
    flex: 0 0 60px; /* Collapsed width, slightly larger for button */
    padding: 15px 5px; /* Reduced padding */
    overflow: hidden; /* Hide overflowing content */
}

.left-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    transition: all 0.3s ease;
}

.left-panel.collapsed .left-panel-header {
    justify-content: center; /* Center button when collapsed */
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

#left-panel-title {
    margin: 0;
    font-size: 1.2em;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.3s ease, max-width 0.3s ease;
    max-width: 100%; /* Default */
}

.left-panel.collapsed #left-panel-title {
    opacity: 0; /* Fade out title */
    max-width: 0; /* Collapse width */
    pointer-events: none; /* Prevent interaction */
}

.left-panel-controls {
    display: flex;
    gap: 5px; /* Spacing between buttons */
}

.toggle-left-panel-btn,
.help-button {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    color: #666;
    padding: 8px;
    border-radius: 8px;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.toggle-left-panel-btn:hover,
.help-button:hover {
    color: #007bff;
    background-color: #e9f5ff;
}

#left-panel-toggle-icon {
    transition: transform 0.3s ease;
}

.left-panel.collapsed #left-panel-toggle-icon {
    transform: rotate(180deg); /* Rotate icon when collapsed */
}

.left-panel .tab-nav,
.left-panel .tab-content,
.left-panel .search-controls,
.left-panel .results-list,
.left-panel .list-limit-message { /* Add list-limit-message here */
    transition: opacity 0.3s ease, height 0.3s ease;
}

.left-panel.collapsed .tab-nav,
.left-panel.collapsed .tab-content,
.left-panel.collapsed .search-controls,
.left-panel.collapsed .results-list,
.left-panel.collapsed .list-limit-message { /* Add list-limit-message here */
    opacity: 0;
    height: 0; /* Collapse height */
    overflow: hidden; /* Hide content */
    pointer-events: none; /* Prevent interaction */
    margin: 0; /* Remove margins */
    padding: 0; /* Remove paddings */
}

.tab-nav {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.tab-nav button {
    flex: 1;
    padding: 12px 15px;
    border: none;
    background-color: transparent;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: #666;
    transition: all 0.3s ease;
    border-radius: 8px 8px 0 0;
}

.tab-nav button.active {
    color: #007bff;
    border-bottom: 3px solid #007bff;
    background-color: #e9f5ff;
}

.tab-content {
    display: none;
    flex-grow: 1; /* 讓內容填充剩餘空間 */
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}

.search-controls {
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap; /* 允許換行 */
    gap: 10px; /* 元素間距 */
}

.search-controls input[type="text"] {
    flex: 1 1 150px; /* 彈性寬度，最小150px */
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 15px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.search-controls button {
    padding: 10px 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.search-button {
    background-color: #007bff;
    color: white;
}

.search-button:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}

.clear-button {
    background-color: #6c757d;
    color: white;
}

.clear-button:hover {
    background-color: #5a6268;
    transform: translateY(-1px);
}

.list-limit-message {
    font-size: 0.85em;
    color: #888;
    margin-top: -10px; /* Adjust spacing */
    margin-bottom: 10px;
    text-align: center;
}

.results-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1; /* 讓列表填充剩餘空間 */
    overflow-y: auto; /* 允許垂直滾動 */
    border: 1px solid #eee;
    border-radius: 8px;
    background-color: #fff;
    max-height: 400px; /* 限制列表高度，以便滾動條出現 */
}

.results-list li {
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.results-list li:last-child {
    border-bottom: none;
}

.results-list li:hover {
    background-color: #f0f8ff;
    transform: translateX(3px);
}

.results-list li.selected {
    background-color: #e0f0ff;
    font-weight: 600;
    color: #007bff;
}

/* 右側面板 */
.right-panel {
    flex: 1; /* 填充剩餘空間 */
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* 允許垂直滾動 */
}

.right-panel-tabs {
    display: flex;
    margin-bottom: 40px;
    border-bottom: 2px solid #eee;
}

.right-panel-tabs button {
    display: flex;
    flex: 1;
    padding: 12px 15px;
    border: none;
    background-color: transparent;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: #666;
    transition: all 0.3s ease;
    border-radius: 8px 8px 0 0;
}

.right-panel-tabs button.active {
    color: #28a745;
    border-bottom: 3px solid #28a745;
    background-color: #eaf7ed;
}

.right-panel-content {
    display: none;
    flex-grow: 1;
    flex-direction: column;
}

.right-panel-content.active {
    display: flex;
}

.initial-message {
    text-align: center;
    font-size: 1.2em;
    color: #888;
}

/* 關係圖 Tab */
.graph-tab h2 {
    margin-top: 0;
    color: #333;
    font-size: 24px;
    margin-bottom: 15px;
}

.node-style-panel {
    background-color: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
    overflow: hidden; /* 隱藏收合內容 */
}

.node-style-panel.collapsed {
    max-height: 50px; /* 收合時的高度 */
    padding-bottom: 0;
}

.node-style-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-weight: 600;
    color: #555;
    margin-bottom: 10px;
}

.node-style-panel-header:hover {
    color: #007bff;
}

.node-style-panel-header .toggle-icon {
    font-size: 1.2em;
    transition: transform 0.3s ease;
}

.node-style-panel.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.node-style-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* 響應式網格 */
    gap: 15px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.node-style-group {
    background-color: #fff;
    border: 1px solid #e9e9e9;
    border-radius: 8px;
    padding: 12px;
}

.node-style-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: #666;
}

.node-style-group input[type="number"],
.node-style-group input[type="color"] {
    width: calc(100% - 22px); /* 考慮 padding */
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 10px;
}

/* New styles for detail visibility controls */
.detail-visibility-controls {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.detail-visibility-controls h4 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1em;
    color: #444;
}

.detail-visibility-controls label {
    display: block; /* Each checkbox on a new line */
    margin-bottom: 5px;
    font-size: 0.95em;
    color: #555;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.detail-visibility-controls input[type="checkbox"] {
    margin-right: 8px;
    transform: scale(1.1); /* Slightly larger checkboxes */
}


.apply-style-button {
    width: 100%;
    padding: 10px 15px;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: background-color 0.3s ease, transform 0.2s ease;
    margin-top: 10px;
}

.apply-style-button:hover {
    background-color: #218838;
    transform: translateY(-1px);
}

.graph-svg-container {
    flex-grow: 1; /* 讓 SVG 容器填充剩餘空間 */
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #fff;
    overflow: hidden; /* 確保 SVG 不會溢出 */
    min-height: 800px; /* 最小高度已調整為 800px (原 400px 的兩倍) */
    position: relative; /* For zoom controls positioning */
    margin-bottom: 20px; /* Space between graph and bar chart */
}

.graph-svg-container svg {
    width: 100%;
    height: 100%;
    display: block; /* 移除 SVG 底部空白 */
}

.zoom-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    padding: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    z-index: 10; /* Ensure controls are above SVG */
}

.zoom-controls button {
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-controls button:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}

.zoom-controls button i {
    font-size: 1em;
}


/* D3 節點和連線樣式 */
.link {
    stroke: #999;
    stroke-opacity: 0.6;
    stroke-width: 1.5px;
}

.node circle {
    stroke: #fff;
    stroke-width: 1.5px;
    cursor: grab;
}

.node text {
    font-family: Arial, sans-serif;
    text-anchor: middle;
    pointer-events: none; /* 讓點擊事件穿透文字到圓圈 */
    text-shadow: 0 0 3px rgba(255, 255, 255, 0.8); /* 文字陰影，提高可讀性 */
}

/* Bar Chart Styles */
#bar-chart-container {
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px; /* Space from graph */
    text-align: center;
}

#bar-chart-container h3 {
    margin-top: 0;
    color: #333;
    font-size: 20px;
    margin-bottom: 15px;
}

.bar-chart-zoom-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.bar-chart-zoom-controls button {
    background-color: #6c757d;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.bar-chart-zoom-controls button:hover {
    background-color: #5a6268;
    transform: translateY(-1px);
}


#event-type-bar-chart {
    width: 100%;
    /* Height is set dynamically by JS, but min-height can be useful */
    min-height: 250px;
    display: block;
}

.x-axis path, .y-axis path {
    stroke: #ccc;
}

.x-axis line, .y-axis line {
    stroke: #eee;
}

.x-axis text, .y-axis text {
    font-size: 12px;
    fill: #666;
}

.bar {
    transition: fill 0.3s ease;
}

.bar:hover {
    fill: #449d44; /* Darker green on hover */
}

.bar-label {
    font-weight: bold;
}

/* Tooltip for bar chart */
.tooltip {
    position: absolute;
    text-align: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border-radius: 4px;
    pointer-events: none; /* Allows mouse events to pass through */
    opacity: 0; /* Hidden by default */
    font-size: 12px;
    z-index: 1001; /* Ensure it's above other elements */
    transition: opacity 0.2s ease;
}


/* 事件列表 Tab */
.event-list-tab h2 {
    margin-top: 0;
    color: #333;
    font-size: 24px;
    margin-bottom: 15px;
}

.event-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
    justify-content: space-between;
}

.event-controls button {
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    background-color: #007bff;
    color: white;
    transition: background-color 0.3s ease;
}

.event-controls button:hover {
    background-color: #0056b3;
}

.selected-count {
    margin-left: auto; /* 推到最右邊 */
    font-weight: 600;
    color: #555;
}

.events-scroll-container {
    flex-grow: 1;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #fff;
    padding: 10px;
}

.events-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.events-list li {
    display: flex;
    align-items: flex-start; /* 頂部對齊 */
    padding: 10px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s ease;
}

.events-list li.separate {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 3px solid #666;
}

.events-list li:last-child {
    border-bottom: none;
}

.events-list li:hover {
    background-color: #f9f9f9;
}

.events-list input[type="checkbox"] {
    margin-right: 10px;
    margin-top: 4px; /* 對齊文字 */
    transform: scale(1.2);
    cursor: pointer;
}

.event-text-content {
    flex-grow: 1;
    cursor: pointer;
    color: #333;
}

.event-text-content .sentence {
    font-weight: 500;
    margin-bottom: 5px;
}

.event-text-content .frequency {
    font-size: 0.85em;
    color: #666;
}

/* 新增事件種類篩選 Tab 樣式 */
.event-type-right-tab {
    padding: 10px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    flex-grow: 1;
    overflow-y: auto;
}

.event-type-right-tab h2 {
    margin-top: 0;
    color: #333;
    font-size: 24px;
    margin-bottom: 15px;
}

.event-type-filter-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
    justify-content: space-between;
}

.event-type-filter-controls button {
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    background-color: #007bff;
    color: white;
    transition: background-color 0.3s ease;
}

.event-type-filter-controls button:hover {
    background-color: #0056b3;
}

.event-type-checkbox-scroll-container {
    flex-grow: 1;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #fff;
    padding: 10px;
}

.event-type-checkbox-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.event-type-checkbox-list li {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.event-type-checkbox-list li:last-child {
    border-bottom: none;
}

.event-type-checkbox-list label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 15px;
    color: #333;
}

.event-type-checkbox-list input[type="checkbox"] {
    margin-right: 10px;
    transform: scale(1.1);
    cursor: pointer;
}

/* Style for clickable event type text in the filter list */
.event-type-clickable-text {
    cursor: pointer;
    padding: 5px; /* Add some padding for easier clicking */
    border-radius: 5px;
    transition: background-color 0.2s ease;
}

.event-type-clickable-text:hover {
    background-color: #e9f5ff; /* Light blue background on hover */
}


/* Container for the sentence list within modal */
.event-type-sentences-scroll-container {
    flex-grow: 1; /* Allows it to take available space */
    overflow-y: auto; /* Enable scrolling */
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #fff;
    padding: 10px;
}

.event-type-sentences-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.event-type-sentences-list li {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 15px;
    color: #555;
    line-height: 1.5;
}

.event-type-sentences-list li:last-child {
    border-bottom: none;
}

.event-type-sentences-list .sentence-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.event-type-sentences-list .sentence-text {
    flex-grow: 1;
}

.event-type-sentences-list .sentence-count {
    font-size: 0.85em;
    color: #888;
    margin-left: 10px;
    white-space: nowrap; /* Prevent wrapping */
}


/* 生平 Tab */
.biography-tab {
    padding: 10px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    flex-grow: 1; /* 填充剩餘空間 */
    overflow-y: auto; /* 允許垂直滾動 */
}

.biography-tab h2 {
    margin-top: 0;
    color: #333;
    font-size: 24px;
    margin-bottom: 15px;
}

.biography-content {
    line-height: 1.8;
    color: #555;
    text-align: justify;
}

/* 模態框 */
.modal-overlay {
    display: none; /* 預設隱藏 */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: #fff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 600px;
    position: relative;
    max-height: 80vh; /* 限制模態框高度 */
    overflow-y: auto; /* 允許模態框內容滾動 */
    animation: fadeInScale 0.3s ease-out;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-close-button {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
    transition: color 0.2s ease;
}

.modal-close-button:hover {
    color: #333;
}

.modal-content h3 {
    margin-top: 0;
    color: #007bff;
    font-size: 22px;
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.modal-detail-item {
    margin-bottom: 12px;
    line-height: 1.6;
}

.modal-detail-item strong {
    color: #555;
    margin-right: 8px;
}

.modal-detail-item span {
    color: #777;
}


/* 響應式設計 */
@media (max-width: 992px) {
    .container {
        flex-direction: column;
        width: 98%;
        margin: 10px auto;
        min-height: unset; /* 移除最小高度限制 */
    }

    .left-panel {
        flex: none;
        width: 100%;
        max-height: 400px; /* Limit height when expanded on mobile */
        padding: 20px; /* Restore padding */
    }

    .left-panel.collapsed {
        max-height: 60px; /* Fixed height for collapsed state on mobile */
        padding: 15px 5px; /* Reduced padding */
    }

    .left-panel.collapsed #left-panel-toggle-icon {
        transform: rotate(90deg); /* Rotate icon for mobile collapsed */
    }

    .left-panel-header {
        justify-content: space-between; /* Always space-between on mobile */
        padding-bottom: 10px;
        border-bottom: 1px solid #eee;
        margin-bottom: 15px;
    }

    .left-panel.collapsed .left-panel-header {
        justify-content: center; /* Center button when collapsed on mobile */
        padding-bottom: 0;
        margin-bottom: 0;
        border-bottom: none;
    }

    .left-panel.collapsed #left-panel-title {
        display: none; /* Hide title on mobile when collapsed */
    }

    .right-panel {
        flex: none; /* 移除彈性填充 */
        width: auto; /* 自動寬度 */
        padding-top: 10px;
    }

    .search-controls {
        flex-direction: column; /* 小螢幕下按鈕垂直排列 */
        gap: 8px;
    }

    .search-controls input[type="text"] {
        width: auto; /* 自動寬度 */
    }

    .search-controls button {
        width: 100%; /* 按鈕佔滿寬度 */
    }

    .node-style-grid {
        grid-template-columns: 1fr; /* 小螢幕下單列顯示 */
    }
}

@media (max-width: 576px) {
    .container {
        margin: 5px auto;
        border-radius: 8px;
    }

    .left-panel, .right-panel {
        padding: 15px;
    }

    .tab-nav button, .right-panel-tabs button {
        font-size: 14px;
        padding: 10px;
    }

    .search-controls input[type="text"],
    .search-controls button {
        font-size: 14px;
        padding: 8px 10px;
    }

    .results-list li {
        font-size: 14px;
        padding: 10px;
    }

    .modal-content {
        padding: 20px;
    }

    .modal-content h3 {
        font-size: 20px;
    }
}

#content-display button.secondary {
    background-color: #8dbf42;
}

#content-display button.secondary:hover {
    background-color: #8da342;
}

#content-display button:disabled {
    background-color: gray;
}

#content-display button:disabled:hover {
    background-color: gray;
}

.graph-tab-back-event-btn {
    background: none;
    border: none;
    color: #007bff;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.graph-tab-back-event-btn:hover {
    background: #f6f6f6;
}

.event-type-label-1 {
    color: darkgoldenrod;
}

.event-type-label-2 {
    color: darkgoldenrod;
}

.event-type-label-3 {
    color: darkgoldenrod;
}

.event-type-label-4 {
    color: darkgoldenrod;
}

.event-type-label-5 {
    color: darkgoldenrod;
}